Hi, I have been looking at VLOOKUP threads across the forum and could not find specific to my needs. I tried to adjust the code elsewhere to my needs, but I am pathetically unsuccessful. I hope somebody could please help me here. Thanks.
I have a notepad file (I could make it excel also if anybody recommends for ease of code) which will have some store names on each line.
I have an excel file that has two sheets. Sheet1 has two columns. First column is store name and second is Revenues. Sheet2 is empty and that is where I want to fill the Sheet1's first and second column but only if sheet1's first column store name is in notepad. Basically notepad is my driving force and then I go to Sheet1 for VLOOKUP. if it exists only then I put in Sheet2.
This is the code I have written until now. Opening notepad, storing in array all works well. Only VLOOKUP is where I need help.
I have a notepad file (I could make it excel also if anybody recommends for ease of code) which will have some store names on each line.
I have an excel file that has two sheets. Sheet1 has two columns. First column is store name and second is Revenues. Sheet2 is empty and that is where I want to fill the Sheet1's first and second column but only if sheet1's first column store name is in notepad. Basically notepad is my driving force and then I go to Sheet1 for VLOOKUP. if it exists only then I put in Sheet2.
This is the code I have written until now. Opening notepad, storing in array all works well. Only VLOOKUP is where I need help.
Rich (BB code):
Sub test()
Dim myFile As String
Dim textline As String
Dim myArray(200) As Variant
Dim x As Long
Dim y As Long
Dim z As Long
Dim activesheetname As String
Dim sheet1sheetname As String
Dim srchRange As Range
myFile = "C:\Desktop\master store.txt"
x = 0
activesheetname = ActiveSheet.Name
sheet1sheetname = "Sheet1"
Open myFile For Input As #1
Do Until EOF(1)
Line Input #1 , textline
myArray(x) = textline
x = x + 1
Loop
Close #1
For y = 0 To x
z = y + 1
Worksheets(activesheetname).Range("A" & z).Value = myArray(y)
'Code for VLOOKUP here
Next y
End Sub
Last edited by a moderator: