Excel Macro Not Working

ydfoley

New Member
Joined
Dec 7, 2016
Messages
3
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?
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
If you are up for an alternate method, here is a non-looping macro for you to consider...
Code:
[table="width: 500"]
[tr]
	[td]Sub GetPassDateRange()
  Dim LR As Long, LCplusOne As Long
  LR = Cells(Rows.Count, "N").End(xlUp).Row
  LCplusOne = Cells(1, Columns.Count).End(xlToLeft).Column + 1
  Application.ScreenUpdating = False
  Cells(1, LCplusOne).Resize(LR) = Evaluate("IF(N1:N" & LR & "=""pass"",""X"","""")")
  Cells(1, LCplusOne).Value = "X"
  Intersect(Columns(LCplusOne).SpecialCells(xlConstants).EntireRow, Range("E1,K1,C1,H1:J1").EntireColumn).Copy Sheets("CurrentReportPeriod").Range("A1")
  Columns(LCplusOne).Clear
  Application.ScreenUpdating = True
End Sub[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,162
Messages
6,170,432
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top