I am new to VBA so all help is much appreciated.
in sheet1,
column AW contains values I wanna to copy, ColumnBN contains criteria like type 1234..
I wanna copy rows in column A that corresponding rows in BN meet criteria such as B =1,
in fact, I wanna to be able to copy cells in AW 4 times based on 4 different criteria type in BN. and Paste into column ABCD in sheet2.
I have developed a VBA but it doesn't seem to be working?
I am not sure if my logic is right. Help is much appreciated
in sheet1,
column AW contains values I wanna to copy, ColumnBN contains criteria like type 1234..
I wanna copy rows in column A that corresponding rows in BN meet criteria such as B =1,
in fact, I wanna to be able to copy cells in AW 4 times based on 4 different criteria type in BN. and Paste into column ABCD in sheet2.
I have developed a VBA but it doesn't seem to be working?
Code:
Sub LastRowInOneColumn()
Dim LastRow As Long
Dim i As Long, j As Long
Dim h
h = 1
'Find the last used row in a Column: column A in this example
With Worksheets("1")
LastRow = .Cells(.Rows.Count, "AW").End(xlUp).Row
End With
MsgBox (LastRow)
With Worksheets("Detail")
LastRow2 = .Cells(.Rows.Count, "BN").End(xlUp).Row
End With
'first row number where you need to paste values in Sheet1'
With Worksheets("2")
j = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
End With
Do While h < LastRow
For i = 1 To LastRow2
With Worksheets("1")
If .Cells(i, 1).Value = "criteria1" Then
.Rows(h).Copy Destination:=Worksheets("2").Range("A" & j)
j = j + 1
End If
End With
Next i
Loop
End Sub
I am not sure if my logic is right. Help is much appreciated