PDA

View Full Version : VBA To Pass A Variable In An Excel Formula



devcon
12-17-2012, 02:11 PM
Good day,

I need to input discount to use as calculation.



Dim Disc As Variant

Disc = InputBox("Enter the value.")
If Disc = "" Then Exit Sub

LastRow = Cells(Rows.Count, "F").End(xlUp).Row
Range("F" & LastRow + 1).Formula = "=sum(F3:F" & LastRow & ") * Disc/100"




Thank you in advance.

Admin
12-17-2012, 06:28 PM
Hi devcon,

Welcome to ExcelFox !!

try


Range("F" & LastRow + 1).Formula = "=sum(F3:F" & LastRow & ") *" & Disc & "/100"

devcon
12-17-2012, 06:44 PM
Thank you very much.
Could you tell me also how to use:


ActiveCell.FormulaR1C1 = "=CONCATENATE(""Discount"","" "",Disc,""%"")"

Admin
12-17-2012, 08:55 PM
Like this


ActiveCell.FormulaR1C1 = "=CONCATENATE(""Discount"","" ""," & Disc & ",""%"")"

devcon
12-17-2012, 09:12 PM
Thank you, excellent.
Have a nice evening.