Problem with Vlookup in VBA

Hi,
I am trying to use Vlookup in a macro but can't get it to Work.
I have a sheet called "Pivot" and a sheet called "Data2".
I build a new sheet called "Raabalance" with data from both sheets with this code:

Sub Opdaterdata()
Dim i_rowidx1, i_rowidx2, i_rowidx3 As Integer
Dim rngstart As Range
Dim primo As Currency
Dim k_nr As String
'On Error GoTo Fejl


Set rngstart = Worksheets("Pivot").Range("A1")
i_data1_idx = rngstart.CurrentRegion.Rows.Count

On Error Resume Next

i_vareliste_idx = 2
For i = 2 To i_data1_idx

  k_nr = Worksheets("Pivot").Cells(i, 1)
  primo = 0
'  primo = [VLOOKUP(k_nr, Data2!A1:X200, 2, FALSE)]
 
' primo = Application.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
' primo = Worksheet.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
'  primo = Application.WorksheetFunction.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
'  primo = Application.Worksheet.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
'  primo = Application.Worksheet.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
 
  'primo = Application.Worksheet.Function.VLookup(k_nr, Tabel_Forespørgsel_fra_EGDTA1, 2, 0)
  primo = Application.WorksheetFunction.VLookup(k_nr, "Data2!a1:x400", 2, 0)
 
  'Kontonr
  Worksheets("Raabalance").Cells(i_vareliste_idx, 1).Value = Worksheets("Pivot").Cells(i, 1)
 
  'Saldi januar-december
  Worksheets("Raabalance").Cells(i_vareliste_idx, 2).Value = Worksheets("Pivot").Cells(i, 2) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 3).Value = Worksheets("Pivot").Cells(i, 3) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 4).Value = Worksheets("Pivot").Cells(i, 4) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 5).Value = Worksheets("Pivot").Cells(i, 5) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 6).Value = Worksheets("Pivot").Cells(i, 6) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 7).Value = Worksheets("Pivot").Cells(i, 7) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 8).Value = Worksheets("Pivot").Cells(i, 8) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 9).Value = Worksheets("Pivot").Cells(i, 9) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 10).Value = Worksheets("Pivot").Cells(i, 10) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 11).Value = Worksheets("Pivot").Cells(i, 11) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 12).Value = Worksheets("Pivot").Cells(i, 12) + primo
  Worksheets("Raabalance").Cells(i_vareliste_idx, 13).Value = Worksheets("Pivot").Cells(i, 13) + primo
 
 
 
  i_vareliste_idx = i_vareliste_idx + 1
 
Next i


End Sub

The Vlookup for the value "Primo" is not working.

Cells from sheet "Pivot":
71112      0      0      -514,66      0      0      -514,66      0      0      -514,66      0      0      0

Cells from sheet "Data2"
71112      -2058,64

Please help...

Regards Bente
AmandinaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saqib Husain, SyedEngineerCommented:
How about a sample file for testing. There might even be a problem with the data.
Saqib Husain, SyedEngineerCommented:
Try

primo = Application.WorksheetFunction.VLookup(k_nr, range("Data2!a1:x400"), 2, 0)
AmandinaAuthor Commented:
Hi Saqib,
I tried your first comment, did not Work.
I have created a sample file with just a little data as it is confidental.
Hope you can help.
R-balance-test.xlsm
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

Saqib Husain, SyedEngineerCommented:
Ok then try

primo = Application.WorksheetFunction.VLookup(Worksheets("Pivot").Cells(i, 1), Range("Data2!a1:x400"), 2, 0)
Ejgil HedegaardCommented:
k_nr is a string, but the lookup values on the sheet are numbers, so k_nr must be converted to a number, or vlookup fails.
primo = WorksheetFunction.VLookup(CLng(k_nr), Range("Data2!A1:X400"), 2, 0)

The table on the sheet is named "Tabel_Forespørgsel_fra_EGDTA3", and for named ranges [ ] brackets can be used, like this.
primo = WorksheetFunction.VLookup(CLng(k_nr), [Tabel_Forespørgsel_fra_EGDTA3], 2, 0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Roy CoxGroup Finance ManagerCommented:
When you are developing code do not use error handlers until the code actually works. If you do then possible error alerts that may help will be stopped.

Instead of VLOOKUP in Excel look at the .Find method in VBA
AmandinaAuthor Commented:
Thanks!
Saqib Husain, SyedEngineerCommented:
Does that mean that the second formula I gave did not work?
AmandinaAuthor Commented:
No, it did not Work.  The problem was the difference between string and numbers.  But thanks
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.