Results 1 to 5 of 5

Thread: VBA To Pass A Variable In An Excel Formula

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0

    VBA To Pass A Variable In An Excel Formula

    Good day,

    I need to input discount to use as calculation.

    Code:
      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.

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi devcon,

    Welcome to ExcelFox !!

    try

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

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Thank you very much.
    Could you tell me also how to use:
    Code:
    ActiveCell.FormulaR1C1 = "=CONCATENATE(""Discount"","" "",Disc,""%"")"

  4. #4
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Like this

    Code:
    ActiveCell.FormulaR1C1 = "=CONCATENATE(""Discount"","" ""," & Disc & ",""%"")"
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Rep Power
    0
    Thank you, excellent.
    Have a nice evening.

Similar Threads

  1. Replies: 4
    Last Post: 06-09-2013, 01:47 AM
  2. Use Native Excel Function Lookup Formula In VBA
    By ramananhrm in forum Excel Help
    Replies: 8
    Last Post: 05-03-2013, 09:10 AM
  3. Find Last Used Row In A Column Using Long Variable
    By xander1981 in forum Excel Help
    Replies: 2
    Last Post: 01-27-2013, 08:53 PM
  4. By pass Outlook security
    By richlyn in forum Outlook Help
    Replies: 0
    Last Post: 03-03-2012, 11:38 PM
  5. Pass Values Between Multiple Userforms
    By Excel Fox in forum Excel and VBA Tips and Tricks
    Replies: 0
    Last Post: 07-24-2011, 03:25 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •