VBA VLookUp...Help needed

Sprucy

Board Regular
Joined
Oct 31, 2005
Messages
92
Hi All,

I've read about 60 post and still no luck!

I need to run a VLookUp via VBA.


Currently using this:
Note:Cell T10 and D10 are in Worksheet "WebDrop"
and A2-K10000 are in "Airports...

T10=VLOOKUP(D10,Airports!$A$2:$K$10000,8,FALSE)

Which I copied from T10.... T1500, my range varies daily between 600-1200 rows and my array table might increase one day...so I want to capture a type of 65536.End(xlUp) formula


Now, in VBA I want something like this...
Do use it, it's just a free flow example..
I've tried about 10 codes plus many modification, I'm losing it!

--------------------
Sub helpPlease()

Sheets("WebDrop").Selects ' need this line, do to previous macros...

With T10:T65536.End(xlUp) ' need my results in these cells

Formula."=vlookup(WebDrop!D10:D65536.End(xlUp),Airports'!A2:K10000,8,False)"
'want to change A2:K10000 to K65536.End(xlUp) if possible..

End With
End Sub
-------------------------

Any other approach are welcomed...

Cheers,
Sprucy
 
Hi Norie,

I did
----------

Sub test()

T10=VLOOKUP(D10,Airports!$A$2:$K$10000,8,FALSE)
Dim ws As Worksheet
Dim LastRow As Long

Set ws = Worksheets("WebDrop")

Set LastRow = ws.Range("D65536").End(xlUp).Row

ws.Range("T10:T" & LastRow) =
"T10=VLOOKUP(D10,Airports!$A$2:$K$10000,8,0)"
 
End

-----------
Plus many twists...
It doens't like the $ absolute values, nor the Set LastRow.


You aksed:
"Are you doing this to get a formula for each line of data returned by a web query?

Yes I am, but I'm not using the WebQuery funtion, it didn't offer the flexibility that I need. Want to see my code?

Can I still use the "adjacent" method you think?

Sprucy

 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Sprucy

Is that the exact code you tried?

Why do you have this?
Code:
"T10=VLOOKUP(D10,Airports!$A$2:$K$10000,8,0)"

How are you actually getting the data?

Are you running a web query through code?
 
Upvote 0
Full Code Below

Hi Again,

Yes, it's all done via VBA.
Sub I) open IE & webpage, submit date in webpage field based on cell value A1
then copy/paste all to WebDrop
Sub II) TrimRange, Column D contains 123- (- is a blank space), this removes the space.
*As the space is trimed-out, my =VlookUp formula in T10:down, goes from N/A to correct ,8,false result.
Sub III)CopyData, select only want I need as a final result and Paste in DCC as value only, no formulas.
Sub IV) to work on a custom header... don't go there....
Sub A & B) save final DCC as seperate Book name = Z1.value
and close MasterFile unsaved.

It works great as it is, but column T could be erased / modify by accident..

See full code below...

---------------------------

Sub I_GetWebData()
'
' DOF Macro
' Macro recorded 11/20/2005 by
'Open site if it requires a PassWord Model or field input validation

Dim ie As Object

Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True

'Go to this Web Page: DCC in this case
ie.Navigate "http://private.intranet.sorry"
'Check for good connection to web page loop!
Do
If ie.ReadyState = 4 Then
ie.Visible = False
Exit Do
Else
DoEvents
End If
Loop

'Wait for window to open!
Application.Wait (Now + TimeValue("0:00:03"))
'MsgBox "Done"
ie.Visible = True
AppActivate ie.LocationName & " - Microsoft Internet Explorer"
'Send date based on Cell A1, date value 12/12/99
SendKeys "{TAB}", True
SendKeys "{TAB}", True
'May need additional SendKeys as needed?
'Determine by the actual key-stroks needed!
SendKeys Sheets("WebDrop").[a1].Value, True
SendKeys "{TAB}", True
SendKeys "{ENTER}", True
Application.Wait (Now + TimeValue("0:00:10"))
With ie
.Visible = True
DoEvents

.ExecWB 17, 2
.ExecWB 12, 2
Sheet2.Paste Sheets("WebDrop").Range("A2")
End With
Application.Wait (Now + TimeValue("0:00:01"))
ie.Quit

Range("H2").Select

Call II_TrimRange

End Sub
Sub II_TrimRange()
'
' TrimRange Macro
' Macro recorded 11/15/2005 by

Sheets("WebDrop").Select
Application.Wait (Now + TimeValue("0:00:02"))

Dim WorkRange As Range

Set WorkRange = Range("D10", Range("D65536").End(xlUp))

For Each Cell In WorkRange
If Cell.Value = "" Then
GoTo Next1
ElseIf IsNumeric(Cell.Value) Then
Cell.Value = Cell.Value * 1
Else
Cell.Value = Trim(Cell.Value)
End If
Next1:
Next Cell

Application.Wait (Now + TimeValue("0:00:02"))

Call III_CopyData

End Sub
Sub III_CopyData()

'Copies Web results from "WebDrop" to "DCC" as values only
Sheets("WebDrop").Select
Range("A10:G65536").Copy

Sheets("DCC").Range("A2").PasteSpecial Paste:=xlPasteAll, Operation:=xlPasteSpecialOperationNone, SkipBlanks:=False, Transpose:=False
'Column T does not come from the Web, it contains the =Vlookup in T10 to T1500, which show as N/A# until the "TrimRange" macro runs...
Range("T10:T65536").Select
Selection.Copy
Sheets("DCC").Select
Range("J2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False


Application.CutCopyMode = False

Range("H2").Select

'Call IV_EditHeader *** Forget the header code, needs work *****

End Sub
Sub B_SaveAs_BackUp()

Call I_GetWebData

Worksheets("DCC").Copy
Dim filename As String, path As String, savefile As String
'Change to "C:\....\......\ **VerifY**
path = "F:\Macros\BU\"
filename = Range("W1").Value
savefile = path & filename & ".xls"
ActiveWorkbook.SaveAs savefile
Workbooks("MasterFile.xls").Saved = True
Workbooks("MasterFile.xls").Close True

End Sub
Sub A_SaveAs_DOF()

Call I_GetWebData

Worksheets("DCC").Copy
Dim filename As String, path As String, savefile As String
'Change to "C:\....\....\ **VerifY**
path = "F:\Macros\DOF\"
filename = Range("Y1").Value
savefile = path & filename & ".xls"
ActiveWorkbook.SaveAs savefile
'saved = false > testing
Workbooks("MasterFile.xls").Saved = True
Workbooks("MasterFile.xls").Close True

End Sub
Sub IV_EditHeader()' Needs work....

Dim mySht As Variant
'Referencing a cell in a header macro
For Each mySht In Worksheets
mySht.Activate
ActiveSheet.PageSetup.RightHeader = strHdr & _
Format(Worksheets("DCC").Range("B2").Value, "dddd, mmm-dd, yyyy")
RightHeader.FontSize = 22

End Sub
 
Upvote 0
Norie, I'm getting there....

OK, the code below works, but I don't understand it and need to modify it...
It inserts the formula in column B, but I want it to Start & End according to the active cells from column A. So if range is A5:A10, the formula should go in B5:B10 only...
Remember that my rows will vary daily.

Thanks again, you must had enough with this post....
Sprucy



-----------------------------
Sub TESTER()
Worksheets("Alpha").Select

lr = Cells(65536, 3).End(xlUp).Row

Range("B4").Formula = "=VLOOKUP(A4,Beta!$A$1:$B$10000,2,FALSE)"
Range("B4").Copy Destination:=Range("b25:b" & lr)


End Sub
--------------------------

'original code below....
'Range("B2").Formula = "=IF(A2=B2," & Chr$(34) & "p. " & Chr$(34) & "&A2," & Chr$(34) & "pp. " & Chr$(34) & "&A2&" & Chr$(34) & "-" & Chr$(34) & "&B2)"
'Range("C2").Copy Destination:=Range("C3:C" & lr)
'Range("C2:C" & lr).Copy
'Sheets("Sheet2").Range("A1").PasteSpecial Paste:=xlPasteValues


'http://www.mrexcel.com/board2/viewtopic.php?t=168458&highlight=insert+formula+range+vba
 
Upvote 0
Does this do what you want?
Code:
Sub TESTER() 
With Worksheets("Alpha")
     lr = .Cells(65536, 1).End(xlUp).Row 

     .Range("B4").Formula = "=VLOOKUP(A4,Beta!$A$1:$B$10000,2,FALSE)" 
     .Range("B4").Copy Destination:=.Range("B5:B" & lr) 

End With
End Sub
 
Upvote 0
Thank you so much. It's perfect!

I owe you, just give me a few years to master this stuff and maybe then I'll be able to help you out.

Thanks for your patience.

Cheers,

Sprucy[/b]
 
Upvote 0

Forum statistics

Threads
1,216,114
Messages
6,128,910
Members
449,478
Latest member
Davenil

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