Hello everyone,
I am a novice at VBA and macros, but I've gone far using this great forum and a lot of trial and error until now.
I'm currently stumped on how to insert a formula using a VBA routine. I have a userform that collects information and a SaveButtonClick() that transfers and the userform data to several cells in column's 1,5 thru 16 in a "data" sheet. However, cells in columns 2,3 & 4 in the data sheet required a vlookup formula and I hoped that adding the formula to the "transfer" syntax in the routine would work. I'm not sure if this method is the best, or if a copy/paste syntax would be more appropriate to insert formulas. Also, the vlookup's lookup_value has to come from the formula's active row (the row it was just copied to), specifically, column 1 or A.
Warm wishes and many thanks on any help you can give!
____________________
Private Sub Savebutton_click()
Dim emptyRow As Long
'Make Data Sheet active
Sheets("Data").Activate
emptyRow = WorksheetFunction.CountA(Range("A:A")) + 2
'Transfer information
Cells(emptyRow, 1).Value = StoreNo.Value
'Cells(emptyRow, 2).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,5))"
'Cells(emptyRow, 3).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,17))"
'Cells(emptyRow, 4).Formula = "=VLOOKUP($A???,'Master Store List'!$A$3:$Q$4000,4))"
Cells(emptyRow, 5).Value = ServiceDate.Value
Cells(emptyRow, 6).Value = StartReg.Value
Cells(emptyRow, 7).Value = StartSF.Value
Cells(emptyRow, 8).Value = SalesReg.Value
Cells(emptyRow, 9).Value = SalesSF.Value
Cells(emptyRow, 10).Value = InvoiceNo.Value
Cells(emptyRow, 11).Value = ReplaceReg.Value
Cells(emptyRow, 12).Value = ReplaceSF.Value
Cells(emptyRow, 17).Value = Comments.Value
If DisplayCheckBox.Value = True Then Cells(emptyRow, 13).Value = Cells(emptyRow, 13).Value & "X"
If ColdBoxCheckBox.Value = True Then Cells(emptyRow, 14).Value = Cells(emptyRow, 14).Value & "X"
If InSchematicCheckBox.Value = True Then Cells(emptyRow, 15).Value = Cells(emptyRow, 15).Value & "X"
If OtherCheckBox.Value = True Then Cells(emptyRow, 16).Value = Cells(emptyRow, 16).Value & "X"
End Sub
Bookmarks