VLOOKUP VBA code results in #NAME?

Davefrisch

New Member
Joined
Jun 19, 2008
Messages
28
At times I will run a macro with a vlookup function and it will return #NAME? in the first destination cell stopping the whole process. Other times it will return #REF. Most of the time it works very well, and I have checked to make sure the array is labeled appropriately each time this occurs.

The interesting part of this whole process is that when I copy and paste the whole excel page into notepad, then open up a new excel and paste the information from notepad into the new excel worksheet the macro code will work just fine. Any insight?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
The main section of the code that stops the process is listed below.

With theSheet.Cells(curRow + 1, (col + 1))
.NumberFormat = "General"
.FormulaR1C1 = "=VLOOKUP(RC[-1],myTab,2,FALSE)"
End With



With theSheet.Cells(curRow - 1, 1)
.Value = "JOB TITLE " & theSheet.Cells(curRow + 1, col).Value & _
" - " & theSheet.Cells(curRow + 1, col + 1).Value
.Font.Size = 18
.Rows.AutoFit
End With


After I select debug, it will highlight the following out of the above code:

.Value = "JOB TITLE " & theSheet.Cells(curRow + 1, col).Value & _
" - " & theSheet.Cells(curRow + 1, col + 1).Value
 
Upvote 0
Dave

What is myTab?

A named range or a variable in the code?
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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