Inserting Input Box in VBA for Excel Macros

Sav09

New Member
Joined
Dec 8, 2018
Messages
3
Hi,
I have a file which needs to be looked up for data in certain fields on a daily basis. I've created a macro in Excel using INDEX & MATCH.
The lookup file name is the same barring the date which changes on a daily basis.
I need to run the macro daily to lookup a new value to the master file, however need to go to the VBA code to change the date & then run the Macro.

I'm a newbie & need help with the code to have an date input box so that i do not need to go to the VBA code to change the date daily. If I could input the date in the input box & then run the macro without going into the VBA code to change the date, it would be of great help. Please assist.

Details of the file code as below (Date highlighted, needs to be changed on a daily basis, post which lookup is done)

Sub Lookup()
'
' Lookup Macro
'

'
ActiveCell.FormulaR1C1 = _
"=INDEX('[RBL Retail Portfolio Dump as on 8-Dec-18.xlsx]Sheet1'!R2C1:R101C6,MATCH(RC2,'[RBL Retail Portfolio Dump as on 8-Dec-18.xlsx]Sheet1'!R2C2:R101C2,0),MATCH(R1C,'[RBL Retail Portfolio Dump as on 8-Dec-18.xlsx]Sheet1'!R1C1:R1C6,0))"
Range("D2").Select
Selection.Copy
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Range("F2").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("D1").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Application.CutCopyMode = False
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("E12").Select
Application.CutCopyMode = False
End Sub
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi
welcome to forum

Try

Code:
Sub Lookup()
'
' Lookup Macro
'


Dim GetInput As Variant


Do
GetInput = InputBox("Enter Date", "Enter Date")
'cancel pressed
If StrPtr(GetInput) = 0 Then Exit Sub


Loop Until IsDate(GetInput)


GetInput = Format(GetInput, "d-mmm-yy")


ActiveCell.FormulaR1C1 = "=INDEX('[RBL Retail Portfolio Dump as on " & GetInput & _
".xlsx]Sheet1'!R2C1:R101C6,MATCH(RC2,'[RBL Retail Portfolio Dump as on " & GetInput & _
".xlsx]Sheet1'!R2C2:R101C2,0),MATCH(R1C,'[RBL Retail Portfolio Dump as on " & GetInput & _
".xlsx]Sheet1'!R1C1:R1C6,0))"


' rest of code



End Sub


Dave
 
Upvote 0
This worked for me.
Thanks Dave, for taking out the time & effort to provide a solution. Appreciate it.
 
Upvote 0
This worked for me.
Thanks Dave, for taking out the time & effort to provide a solution. Appreciate it.

Hi Dave,

One more query.
If the input date format of the file changes to ddmmyyyy instead of the earlier one(DD-MM-YY), how would the code change.

Regards
Savio
 
Upvote 0
just change to the required format

Rich (BB code):
GetInput = Format(GetInput, "ddmmyyyy")

Dave
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,633
Members
452,661
Latest member
Nonhle

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