I have single values in Ad Group column that I need to duplicate in the blank cells in the rows below. There should be 3 of each Ad Group name.
My first screenshot shows how it currently is:
My second screenshot shows how I need it:
There are 30k rows so I need a formula or dynamic way to achieve this.
Here is my answer:
Using VBA:
Sub selectBlankCells()
Dim r 'to store the number of the last row of data
Dim rng As Range
r = Range("A1").End(xlDown).Row 'to find the last row
Set rng = Range(Cells(1, 2), Cells(r, 2)) ' set the range of column B, of the data
rng.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C" ' this is where you put the formula to
'set the data of above cell in every empty cell of
'column B
End Sub
Or you can use the Excel option:
Select the the data of column B, from the last row to the cell B1, then press F5, and this window appears.
Then press Special...
After that, select Blanks and OK
You will select only the blank cells, and then you can put the formula to link the above cell from the active cell.
This way using ([Ctrl]+[Enter] is needed to put the formula into all of the cells at once as Jeeped says):
You will get this:
Related
I am working with a large dataset (500+ columns X 10,000 rows). I am trying to get a count and sum of all variables within a row. All column names are listed on a separate worksheet/table. Whats the best way to go about it? Thanks
Main Data: Raw Data
Summary: Where I am trying to get the count and sum
Formula:
One way with ms365 could be:
Formula in G3:
=LET(z,B2:E7,WRAPROWS(TOCOL(VSTACK(TAKE(z,1),BYCOL(DROP(z,1),LAMBDA(x,COUNT(x))),BYCOL(DROP(z,1),LAMBDA(y,SUM(y)))),,1),3))
It can be less verbose, but this way you'd just need to select B2:E7 once, on whatever worksheet it is located.
PowerQuery:
Another way would be PowerQuery, where you'd:
Select (a single cell or ) the whole range B2:E7;
On the 'Data' tab, click 'From Table/Range' in the 'Get & Transform Data' group;
Choose to include headers, and hit 'OK'. PQ launches;
Select all column and in the 'Transform' tab, click 'Unpivot Columns' under the 'Any Column' group;
Select the 1st column, 'Attribute' in this case, and on the same tab 'Transform' choose to 'Group By' under the 'Table' group;
Hit the advanced option and create two aggregations before hitting 'OK':
Close and load data back to Excel.
If you Summary (Trying) column name is not fixed ... something like this :
So, the Sheet1 is data with 4 columns header, but in Sheet2, the "demand" is only 3 columns and not in sequence. (and later on, maybe the "demand" change to only 2 columns, later on the "demand" to all 4 columns, etc and also the header name always change).
The expected result in Sheet2:
So, if the cell has value, even if it's a zero value in the data column A then it is counted. Only a blank cell is not counted.
Sub test()
Dim rgSrc As Range: Dim rgTrg As Range: Dim c As Range
Set rgSrc = Sheets("Sheet1").UsedRange 'change as needed
With Sheets("Sheet2")
Set rgTrg = .Range("A2", .Range("A2").End(xlDown)) 'change as needed
End With
For Each cell In rgTrg
Set c = rgSrc.Rows(1).Find(cell.Value, lookat:=xlWhole)
If Not c Is Nothing Then
With rgSrc.Columns(c.Column)
cell.Offset(0, 1).Value = Application.CountA(.Cells) - 1
cell.Offset(0, 2).Value = Application.Sum(.Cells)
End With
End If
Next
End Sub
rgSrc is the range of the data in sheet1.
rgTrg is the range from cell A2 to whatever lastrow in sheet2. The code assumed that there'll be no blank cell in between data in column A of sheet2.
It loop to each cell in rgTrg (loop to each demanded header name), then put the count of the data in rgSrc with the looped cell value (which is the header name) in cell.offset(0,1) and put the sum of it in cell.offset(0,2).
Looking for some help here since most answers delete the entire row. Thanks in advance!
This is what my table looks like, I'm looking to delete a row (but only from column A to K, not entire row), if a cell is blank in column D.
Data is dynamic, will change each time, but it should always have a blank in cell D. If not, looking for the code to just continue on.
So highlighted D3 is blank, I want it to delete A3 to K3.
.
.
You could filter cell D2 for (Blanks) to have them all -- mind you there most likely will be a blank cell in column B, but I essentially want to delete all this data filtered.
Is is ColumnK or ColumnF. Something like this, maybe. Just change to suit your needs.
Option Explicit
Sub BlankRowDeletion()
'Declaring variables
Dim LastRow As Long
Dim Rng As Range
'Getting row number of last cell
LastRow = Range("A3").SpecialCells(xlCellTypeLastCell).Row
'Selecting all data
Set Rng = Range("A3:K" & LastRow)
'Selecting Blank cells
Rng.SpecialCells(xlCellTypeBlanks).Select
'Deleting complete row
Selection.EntireRow.Delete
Range("A3").Select
End Sub
Consider the following table:
I have a series of blank cells with missing data. From this missing data I only have the year in the next column. I need to fill any blank cells with a standard day/month of 30/06. The year of each cell however needs to be the year in the next column. The attached file shows how my data is arranged. So at cell B 2091, the date shall be 30/06/2011 while for cell B 2098 the date shall be 30/06/2018 and at cell B 2100 the date shall be 30/06/2008.
Filter on the blank cells in column B. Then, in the topmost cell (which I'll assume to be B1 but will likely be different), enter a formula similar to the following and fill down
=DATE(C1,6,30)
where the row number in C1 is the same as your first row of data.
You can achieve this with a helper column (any blank column in the same worksheet where you need the dates). In that column enter this formula in the first cell (here in row 2) and copy down.
=IF(ISBLANK(B2),DATE(C2,6,30),B2)
Then copy the Values from the helper column to the date column and delete the helper.
Below is a small macro that is doing the same job. It needs no helper column and over-writes your existing blanks. Before you run it make sure to check the values of the 2 constants at the top and the name of the worksheet (especially the latter!) against your requirements.
Sub WriteStandardDate()
'293
Const FirstDataRow As Long = 2 'change to suit
Const DateClm As Long = 2 'change to suit
' year column must be adjacent to DateClm
Dim R As Long
Dim Arr As Variant
Dim Rng As Range
With Worksheets("Sheet1") ' change name as required
Set Rng = .Range(.Cells(FirstDataRow, DateClm), _
.Cells(.Rows.Count, DateClm).End(xlUp)) _
.Resize(, 2)
Arr = Rng.Value
For R = 1 To UBound(Arr)
If IsEmpty(Arr(R, 1)) Then
Arr(R, 1) = DateSerial(Arr(R, 2), 6, 30)
End If
Next R
Rng.Value = Arr
End With
End Sub
Update: I used the formula suggested by Variatus: =IF(ISBLANK(B2),DATE(C2,6,30),B2) and worked fine through a helper column. There was no need to copy / paste the new dates into the Dates column. I just used the helper column as the new Dates column since full dates from the original column were not changed and got inserted in the helper column thanks to the IFBLANK portion of the formula. Thanks.
I am new to VBA Excel and wondering if you can help.
I have tried typing something similar to this =IF(C10,(ROW(A10)-ROW(A$9)),"") and it works. However, the downside to this is you have to enter this formula into every cell that you want to auto populate. I am trying to find a macro code in Excel so that cells will auto number 1,2,3,etc. whenever the adjacent column contains data?
For example, when a user enters data into B1, A1 will automatically be populated to 1. Then when users enters data into B2, A2 will automatically be populated to 2 and so on. Then when users delete data from B column, adjacent column in A will not contain a number.
Enter this into A1 based on what you said:
=if(isblank(B1),"",row())
If you want this in VBA you can use the following, but this assumes your data starts at Row 1. If it you want the numbering at Row 2 to start as 1, just add "-1" after the RngA part.
Sub Serial()
Dim RngA As Long, LastRow as Long 'Declares the variables used
LastRow = ActiveSheet.Cells(Cells.Rows.Count, "B").End(xlUp).Row 'This finds the last row in Column B where the loop will end.
For RngA = 1 To LastRow ' This loops from the first row to the last cell filled in column B
If Cells(RngA, 2) <> "" Then ' If Column B is blank, skip this row
Cells(RngA, 1).Value = RngA 'Column B was not blank, so put the row number in column A
End If
Next
End Sub
In Microsoft Excel, I have two columns in a sheet. The first column has values like B2,A13,BB125 and the next column has some number values like 12,569,78.
I want to find the cell from the first column in another sheet and to that cell add the value from the second column.
Does anyone know how to do that?
You can retrieve the value from the cell in column A and pass it to Range() to address the cell in your other sheet.
For example:
' Use A1 as an example...
Dim r As Range
Set r = Range("A1")
' Use A1's value to address a cell on Sheet2 and assign the value from B1...
Sheet2.Range(r.Value).Value = r.Offset(, 1).Value