LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Vlookup error in VBA, 2042

You shouldn't have to use "on error resume next" when you use
application.vlookup() in your code. You would need it for
application.worksheetfunction.vlookup(), though.

Where is your code located?

When it was in a general module, it worked fine for me.

What do you have checked (in the VBE):
Tools|Options|General tab|error trapping section
I have "break in class module" checked.




elf27 wrote:

I'm trying to do a simple vlookup in Excel but getting an error when I step
through the process...
Anyone know what's wrong?

Public Sub SyncSheet2()
Const ArtCol As String = "A" '<=== change to suit
Dim i As Long
Dim T As Long
Dim FirstRow As Long
Dim LastRow As Long
Dim NextRow As Long
Dim CellVal As Variant
Dim DataCol As Variant
Dim ArtNum As String
Dim LookUpRng As Range
Dim sh As Worksheet

Set sh = Sheet2

With sh

i = 1
Do Until FirstRow < 0
If IsNumeric(.Cells(i, "A")) Then
If .Cells(i, "A").Value 0 Then
FirstRow = i
End If
Else: FirstRow = 0
End If
i = i + 1
Loop
i = 1
Do Until LastRow < 0
If .Cells(i + 2, "A").Value = "" Then
LastRow = i + 1
Else: LastRow = 0
i = i + 1
End If
Loop
End With

With sh
T = 2

For i = FirstRow To LastRow
ArtNum = sh.Cells(i, ArtCol)
CellVal = Application.VLookup(ArtNum, Sheet1.Range("A1:V306"), T,
False)
If IsError(CellVal) Then
CellVal = "Error"
End If
With sh.Cells(i, "B")
.Value = CellVal
End With


--

Dave Peterson


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
error 2042 with vlookup Bert Excel Programming 6 February 16th 09 05:52 PM
Error 2042 Fred Excel Programming 1 June 21st 08 12:20 AM
vlookup error 2042 jer Excel Programming 0 November 27th 06 02:31 PM
Excel xlodbc error 2042 with SQLRetrieve ALK[_2_] Excel Programming 0 July 28th 05 03:05 PM
Error 2042 Barbara[_3_] Excel Programming 1 September 8th 03 08:16 PM


All times are GMT +1. The time now is 01:17 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"