Macro to vlookup a different range each month

psrs0810

Well-known Member
Joined
Apr 14, 2009
Messages
1,109
I need to create a macro that will do a vlookup from one workbook to another where the range will change every month.

How can I setup this macro so when there is a new month, the range changes?

This is what I have so far, but it does not handle the change for a new month.

Sub IPOPBudgetData()
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p> </o:p>
Dim strFile As String
Dim Tempfile As Workbook
Dim LR As Long

strFile = Application.GetOpenFilename
Workbooks.Open strFile
Set Tempfile = ActiveWorkbook
<o:p> </o:p>
Sheets("IP").Select
<o:p> </o:p>
Windows("Allowance Macro.xls").Activate
Sheets("By_Trans_Code").Select
Range("E2").Select
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("E2:E" & LR)
.Formula = "=VLOOKUP(RC[-4],'[2011 Allowance Budget by Trans Code.xls]OP'!C3:C17,15,0)"
.Value = .Value
End With
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
Application.CutCopyMode = False
Tempfile.Close
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
I am looking to add something like this:


Sub test()
Dim varDate
varDate = Application.InputBox("Enter the date of the target workbook's name", "Enter Date", Format(Date, "mm.dd.yy"), , , , , Type:=2)
If IsDate(Replace(varDate, ".", "/")) Then
varDate = Format(CDate(Replace(varDate, ".", "/")), "mm.dd.yy")
Else
MsgBox "Invalid date entered - exiting sub!": Exit Sub
End If
Range("B1").FormulaR1C1 = "=VLOOKUP(RC[-1],'[PN " & varDate & ".xls]Sheet1'!C1:C2,2,0)"

End Sub

but instead of mm.dd.yy - I would like to enter Jan OP, Feb OP, Mar OP - etc.
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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