Monday, 26 August 2013

Modify Macro to put vlookup results in empty column for next month

Modify Macro to put vlookup results in empty column for next month

I am trying to automate a monthly report that I run. Each month, I run a
query (embedded into a separate tab) and then use vlookup to move the
values into the column for the current month.
I want to create a macro to move the values for the current month, but
what I need to figure out, is how to modify the macro to check if a column
for a month has been filled out, and if it is, then to put the monthly
numbers in the column to the right (next month). I have been researching
this for a while, but I have very little VBA experience and get stuck when
I run into errors. I know I can use the "IsEmpty" function, but I'm not
sure of the best way to use it.
Here is a copy of the Macro:
Range("N6").Select
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-10],'ENT - Query
Totals'!C2:C4,3,FALSE)"
Range("N6").Select
ActiveWindow.SmallScroll Down:=-9
Range("N6").Select
Selection.AutoFill Destination:=Range("N6:N82"), Type:=xlFillDefault
Range("N6:N82").Select
ActiveWindow.SmallScroll Down:=-60
Range("N6:N82").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("O64").Select
Cells.Replace What:="#N/A", Replacement:="0", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
End Sub
So basically, I want to check if "N6" is empty. If it is, the macro would
use vlookup to move the data from the query tab into the column "N". If it
is not empty, I want it to copy the data from the query tab into column
"O", etc.
Any help or guidance will be greatly appreciated while I continue to learn
VBA

No comments:

Post a Comment