VBA Hlookup what is wrong?

Myproblem

Board Regular
Joined
May 24, 2010
Messages
198
I have code under which should give me Hlookup formula.
But something is wrong.
Can anyone help me to write Hlookup formula? (I need to write Hlookup formula in Cell D10, like D10=HLOOKUP(D10;F_pre_mj;10;False)
any suggestions?


Sub copy_prev_month()
Range("D10").FormulaR1C1 = "=HLOOKUP(R[-10]C1;F_pre_m;10;false)"

Range("D10:D20").Copy
Range("F10:F20").PasteSpecial Paste:=xlPasteFormulas
Range("H10:H20").PasteSpecial Paste:=xlPasteFormulas
End Sub
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You can't put a formula in row 10 that references a row -10 from that row, that's row 0, which doesn't exist.
 
Upvote 0
You can't put a formula in row 10 that references a row -10 from that row, that's row 0, which doesn't exist.

I changed it from Range("D10").FormulaR1C1 = "=HLOOKUP(R[-10]C1;F_pre_m;10;false)"
to Range("D10").FormulaR1C1 = "=HLOOKUP(R[-9]C1;F_pre_m;10;false)"
but it is still wrong

any tips?
 
Upvote 0
Sure, put the formula in D10 that should actually be there, then paste that formula here so we can see the real answer.
 
Upvote 0
thx you jbeaucaire, i solved it :), the code:
Sub copy_prev_month()
Range("D10") = "=HLookup(D$1, F_prev_m, $K10, False)"
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,286
Members
452,902
Latest member
Knuddeluff

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