MixedUpExcel
Board Regular
- Joined
- Apr 7, 2015
- Messages
- 222
- Office Version
- 365
- Platform
- Windows
Hi,
When I run this code.
My aim is to have a user be able to pull data based on their selected criteria from the inputbox from a closed file (which isn't going to be opened).
That closed file is updated (with a new file name) each week, hence the user having to select the file initially to obtain the file name.
The vlookup is resulting in part of the folder / file name being input twice into the formula.
Please can you advise where my mistake is?
Thanks in advance.
Simon
When I run this code.
My aim is to have a user be able to pull data based on their selected criteria from the inputbox from a closed file (which isn't going to be opened).
That closed file is updated (with a new file name) each week, hence the user having to select the file initially to obtain the file name.
The vlookup is resulting in part of the folder / file name being input twice into the formula.
Please can you advise where my mistake is?
Thanks in advance.
Simon
Code:
Sub data_file()
Dim MYVALUE As Variant
Dim FName As Variant
Dim Msg As String
workbooknamemain = ActiveWorkbook.Name
MYVALUE = InputBox("PLEASE SELECT JUST THE NUMBER FOR YOUR REQUIRED OPTION" & vbCrLf & _
"1 - STATUS" & vbCrLf & _
"2 - DESCRIPTION" & vbCrLf & _
"3 - COST PRICE" & vbCrLf & _
"4 - SELL PRICE" & vbCrLf & _
"5 - RRP EX VAT" & vbCrLf & _
"6 - SALES RANGE")
If MYVALUE = 1 Then
mycol = 4
ElseIf MYVALUE = 2 Then
mycol = 3
ElseIf MYVALUE = 3 Then
mycol = 9
ElseIf MYVALUE = 4 Then
mycol = 10
ElseIf MYVALUE = 5 Then
mycol = 27
ElseIf MYVALUE = 6 Then
mycol = 25
End If
FName = Application.GetOpenFilename()
If FName <> False Then
Else
End If
MsgBox FName
Range("I2").Value = FName
Dim MyRange As Range
Set MyRange = Selection
Selection.FormulaR1C1 = _
"=VLOOKUP(RC[-1],'[" & FName & "]'!C5:C32," & mycol & ",0)"
End Sub