Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Excel Formula in Macro (Excel 2002)

    Hi,
    I have the following code in a macro attached to an Excel spreadsheet:
    lngRow = 1
    Do
    If Range("A" & lngRow) <> "" Then
    Range("Q" & lngRow).Select
    ActiveCell.FormulaR1C1 = "=RC[-9]&RC[-8]&RC[-7]"
    End If
    lngRow = lngRow + 1
    Loop Until Range("A" & lngRow) = ""

    It works great, however instead of having the actual formula show up in the cell, can I tweak the code some how to generate just the value of the formula... for example, the formula that shows up due to my code above is as follows =A1&B1&C1..... if cell A1was 75 and B1 was M and C1 was CORP, then the result would be 75MCORP... I don't want the formula to be there... I'd just like the answer. I suppose I could do a copy & paste values as part of the code, but I'm guessing there's a more direct way of doing it?!?!
    Thanks!!
    Lana

  2. #2
    3 Star Lounger
    Join Date
    Jul 2002
    Location
    Ankeny, Iowa, USA
    Posts
    344
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Re: Excel Formula in Macro (Excel 2002)

    Hi Hans,
    Thanks for the info! Sorry if I complicated it by having my example refer to A1, B1, & C1, when in reality it was H1, I1, & J1... I was trying to make it easier for example purposes... oops! Anyway, I took part of your code and put it in (see below) and it worked perfect... I knew there had to be better way then my original approach (which of course was derived partially from a recorded macro and partially from some VBA code you had provided in to me in the past)!
    Thanks as usual Hans!
    Lana
    'Concatenate columns to create unit
    lngRow = 1
    Do
    If Range("A" & lngRow) <> "" Then
    Range("Q" & lngRow) = Range("H" & lngRow) & Range("I" & lngRow) & Range("J" & lngRow)
    End If
    lngRow = lngRow + 1
    Loop Until Range("A" & lngRow) = ""

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Excel Formula in Macro (Excel 2002)

    Edited by HansV to correct mistake in original reply

    Since your formula acts on column Q, the formula refers to columns H, I and J, not to columns A, B and C. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

    If you want to set the value instead of the formula, this is the code:

    lngRow = 1
    Do While Range("A" & lngRow) <> ""
    Range("Q" & lngRow) = Range("H" & lngRow) & Range("I" & lngRow) & Range("J" & lngRow)
    lngRow = lngRow + 1
    Loop

  4. #4
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Excel Formula in Macro (Excel 2002)

    Around here, you usually get what you ask for, not necessarily what you want! <img src=/S/yep.gif border=0 alt=yep width=15 height=15> <img src=/S/grin.gif border=0 alt=grin width=15 height=15>
    Legare Coleman

Posting Permissions

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