VBA Formula problem

cdragone

New Member
Joined
Jul 8, 2011
Messages
8
Hey
Theres a problem which i do not know how to fix. I've got most of the program i made working but i just cant get the VLOOKUP to work.
The program shall be used on multiple OS platforms (Win Vista, Win 7, Mac OS X 10). The excel version is 2007.
Anyway heres the code:
Code:
Private Sub InsertData_Click()
Dim lRow As Long
Dim fRow As Long
Dim ws As Worksheet
Set ws = Sheet1
lRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
fRow = Range("A65536").End(xlUp).Row + 1
ws.Cells(lRow, "A") = Me.BillNrBox.Value
ws.Cells(lRow, "B") = Me.SenderBox.Value
ws.Cells(lRow, "C") = Me.ReceiverBox.Value
ws.Cells(lRow, "D") = Me.KgBox.Value * 1
ws.Cells(lRow, "E") = Me.M3Box.Value * 333
ws.Cells(lRow, "F") = Me.LVBox.Value * 1850
ws.Cells(fRow, "G").Formula = "=MAX(D" & fRow & ":F" & fRow & ")"
[COLOR="Red"]ws.Cells(fRow, "H").Formula = "=VLOOKUP(G" & fRow & ";Prices!$A$2:$B$56;TRUE)"[/COLOR]
BillNrBox.Value = vbNullString
SenderBox.Value = vbNullString
ReceiverBox.Value = vbNullString
KgBox.Value = "0"
M3Box.Value = "0"
LVBox.Value = "0"
HelpBox.Caption = "Info added to Worksheet"
End Sub
At first the formula on G column did not also work, but got it working via searching. All help is appreciated.

PS: Runtime error 1004
Application-defined error or object-defined error

Thank you in Advance
-C
 
Acctually tried all of what you sayd before.
Code:
ws.Cells(fRow, "H").Formula = "=VLOOKUP(G" & Trim(Str(fRow)) & "with ,Prices!$A$2:$B$56 with ,2 with ,TRUE)"
Thats the only row, which still has the same error
This line here, has no problems:
Code:
ws.Cells(fRow, "G").Formula = "=MAX(D" & Trim(Str(fRow)) & ":F" & Trim(Str(fRow)) & ")"
And 'hinnad' = Prices!$A$2:$B$56

Any other ideas?
 
Last edited:
Upvote 0

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Where do all these "with"s keep coming from? Everytime you show code, it's different somehow...
 
Upvote 0
Im really sorry, i totally didnt notice the "with ,". i copyed it and had to run after i modded it and posted here. And true, now it works all fine!
Thank you everyone for all the effort
 
Upvote 0

Forum statistics

Threads
1,224,525
Messages
6,179,317
Members
452,905
Latest member
deadwings

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