Worksheet Function Help

Hernan_g_f

New Member
Joined
Jul 26, 2022
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I'm writing the following code:

Dim rng3, rng4 As Range
Set rng3 = sh.Range("E16:H2500")
Set rng4 = sh.Range("E14:H14")

Dim x1 As Long

x1 = 100 / sh.Cells(14, 9).Value


For i = 1 To awx1

For j = 1 To 4

If rng1.Cells(i, 1).Value > 0 Then
rng3.Cells(i, j).Value = WorksheetFunction.VLookup(rng1.Cells(i, 1).Value, rng2, rng4.Cells(1, j).Value, 0) * x1
Else
rng3.Cells(i, j).Value = ""
End If


Next j

Next i

But x1 is incorrect. How can I write the correctly code so the line: rng3.Cells(i, j).Value = WorksheetFunction.VLookup(rng1.Cells(i, 1).Value, rng2, rng4.Cells(1, j).Value, 0) * x1

Thank your very much!
Hernán
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Does rng4.Cells(1, j).Value return a number and is the number of a column in the range rng2 ?
You are not showing the Dim statement for rng1 & rng2.
What is awx1 ?
What is in sh.Cells(14, 9).Value ?

Make sure you have the VLookup working in Excel before trying to convert it to VBA.
 
Upvote 0
Solution
Dear Alex Blakenburg, thank you for the suggestions teacher. I had resolved the trouble last week!
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,684
Members
449,463
Latest member
Jojomen56

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