I have never written a loop in Excel and hope I can get some assistance.
I have a spreadsheet named “AccessDBLink” that imports a table from Access. The last three columns of the spreadsheet are calculation fields. I need a macro that will take note of column “N”. If the cell says “Pass”, columns E, K, C, H, I & J will be copied to worksheet “CurrentReportPeiod” in columns A,B,C,D,E & F.
This is what my current macro says.
Sub GetPassDateRange()
Dim LR As Long, i As Long
With ActiveSheet
LR = .Range("N" & Rows.Count).End(xlUp).Row
For i = 1 To CurrentReportPeriod
If .Range("N" & i).Value = "Pass" Then
.Range("E" & i).Copy
Sheets("CurrentReportPeriod").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("K" & i).Copy
Sheets("CurrentReportPeriod").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
End With
End Sub
Nothing happens. I get no information copied over to the spreadsheet. What am I failing to do?
I have a spreadsheet named “AccessDBLink” that imports a table from Access. The last three columns of the spreadsheet are calculation fields. I need a macro that will take note of column “N”. If the cell says “Pass”, columns E, K, C, H, I & J will be copied to worksheet “CurrentReportPeiod” in columns A,B,C,D,E & F.
This is what my current macro says.
Sub GetPassDateRange()
Dim LR As Long, i As Long
With ActiveSheet
LR = .Range("N" & Rows.Count).End(xlUp).Row
For i = 1 To CurrentReportPeriod
If .Range("N" & i).Value = "Pass" Then
.Range("E" & i).Copy
Sheets("CurrentReportPeriod").Range("A" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
.Range("K" & i).Copy
Sheets("CurrentReportPeriod").Range("B" & Rows.Count).End(xlUp).Offset(1).PasteSpecial Paste:=xlPasteValues
End If
Next i
End With
End Sub
Nothing happens. I get no information copied over to the spreadsheet. What am I failing to do?