Hi all,
I am trying to write a logic, where if cell value in column A = "A", the data from that whole row needs to be copied to the lastrow +1 / the first empty row below. As a step 2, the values of cells in column A within the newly copied range or the original range of cells with value A to replaced with value "D".
Thank you.
The code which is incomplete:
The dataset sample
I am trying to write a logic, where if cell value in column A = "A", the data from that whole row needs to be copied to the lastrow +1 / the first empty row below. As a step 2, the values of cells in column A within the newly copied range or the original range of cells with value A to replaced with value "D".
Thank you.
The code which is incomplete:
VBA Code:
lastRow = Cells(Rows.Count, 1).End(xlUp).Row
' Loop through each row
For x = 2 To lastRow
ThisValue = Cells(x, 4).Value
If ThisValue = "A" Then
Cells(x, 1).Resize(Y, 1).Copy 'I am trying to copy the whole range in one go because lines of data with value "A" in cells in Column A will be one after another but haven't yet defined "Y"
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
End If
Next x
The dataset sample
Commodity | Pillar | Price |
A | Sep20 | 3.485 |
A | Oct20 | 3.5775 |
A | Nov20 | 3.5775 |
B | Jan22 | 9.415 |
B | Feb22 | 9.265 |
B | Mar22 | 9.265 |
B | Apr22 | 9.2375 |
B | May22 | 9.2375 |
C | Mar27 | 6.1033 |
C | Apr27 | 6.1101 |
C | May27 | 6.1101 |
C | Jun27 | 6.1133 |
C | Jul27 | 6.1133 |