+ Reply to Thread
Results 1 to 5 of 5

Macro to take selected cells times a selected cell

  1. #1
    Craig
    Guest

    Macro to take selected cells times a selected cell

    I have a row of hardcoded numbers in cells A1, A2, A3 A4. I want to be able
    to highlight(select) the above cells and have them be multiplied by B2. Is
    this possible.

    I have a huge worksheet that has all hardcoded numbers that I need to be
    multiplied by a certain cell. In the above instance B2.

    So instead of going into each cell, placing an "=" in front of the value and
    then putting an * B2 at the end of the value in each cell, I am trying to
    figure out how set up a macro and do it automatically.



  2. #2
    Bob Phillips
    Guest

    Re: Macro to take selected cells times a selected cell

    Sub MultiplyByB2()
    Dim cell As Range

    For Each cell In Selection
    If IsNumeric(cell.Value) Then
    cell.Formula = "=" & cell.Value & "*B2"
    End If
    Next cell
    End Sub


    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Craig" <[email protected]> wrote in message
    news:[email protected]...
    > I have a row of hardcoded numbers in cells A1, A2, A3 A4. I want to be

    able
    > to highlight(select) the above cells and have them be multiplied by B2.

    Is
    > this possible.
    >
    > I have a huge worksheet that has all hardcoded numbers that I need to be
    > multiplied by a certain cell. In the above instance B2.
    >
    > So instead of going into each cell, placing an "=" in front of the value

    and
    > then putting an * B2 at the end of the value in each cell, I am trying to
    > figure out how set up a macro and do it automatically.
    >
    >




  3. #3
    Gord Dibben
    Guest

    Re: Macro to take selected cells times a selected cell

    Craig

    Sub test()
    Dim ocell As Range
    For Each ocell In Selection
    ocell.Value = ocell.Value * Range("B2").Value
    Next ocell
    End Sub

    Manually you can select B2 and copy.

    Then select all the cells to change and paste special>multiply>OK>Esc


    Gord Dibben Excel MVP

    On Sun, 23 Oct 2005 17:56:12 -0500, "Craig" <[email protected]> wrote:

    >I have a row of hardcoded numbers in cells A1, A2, A3 A4. I want to be able
    >to highlight(select) the above cells and have them be multiplied by B2. Is
    >this possible.
    >
    >I have a huge worksheet that has all hardcoded numbers that I need to be
    >multiplied by a certain cell. In the above instance B2.
    >
    >So instead of going into each cell, placing an "=" in front of the value and
    >then putting an * B2 at the end of the value in each cell, I am trying to
    >figure out how set up a macro and do it automatically.
    >



  4. #4
    Craig
    Guest

    Re: Macro to take selected cells times a selected cell

    Thanks! Exactly what I needed!


    "Bob Phillips" <[email protected]> wrote in message
    news:[email protected]...
    > Sub MultiplyByB2()
    > Dim cell As Range
    >
    > For Each cell In Selection
    > If IsNumeric(cell.Value) Then
    > cell.Formula = "=" & cell.Value & "*B2"
    > End If
    > Next cell
    > End Sub
    >
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Craig" <[email protected]> wrote in message
    > news:[email protected]...
    >> I have a row of hardcoded numbers in cells A1, A2, A3 A4. I want to be

    > able
    >> to highlight(select) the above cells and have them be multiplied by B2.

    > Is
    >> this possible.
    >>
    >> I have a huge worksheet that has all hardcoded numbers that I need to be
    >> multiplied by a certain cell. In the above instance B2.
    >>
    >> So instead of going into each cell, placing an "=" in front of the value

    > and
    >> then putting an * B2 at the end of the value in each cell, I am trying to
    >> figure out how set up a macro and do it automatically.
    >>
    >>

    >
    >




  5. #5
    Craig
    Guest

    Re: Macro to take selected cells times a selected cell

    Thanks for the help!


    "Gord Dibben" <gorddibbATshawDOTca> wrote in message
    news:[email protected]...
    > Craig
    >
    > Sub test()
    > Dim ocell As Range
    > For Each ocell In Selection
    > ocell.Value = ocell.Value * Range("B2").Value
    > Next ocell
    > End Sub
    >
    > Manually you can select B2 and copy.
    >
    > Then select all the cells to change and paste special>multiply>OK>Esc
    >
    >
    > Gord Dibben Excel MVP
    >
    > On Sun, 23 Oct 2005 17:56:12 -0500, "Craig" <[email protected]> wrote:
    >
    >>I have a row of hardcoded numbers in cells A1, A2, A3 A4. I want to be
    >>able
    >>to highlight(select) the above cells and have them be multiplied by B2.
    >>Is
    >>this possible.
    >>
    >>I have a huge worksheet that has all hardcoded numbers that I need to be
    >>multiplied by a certain cell. In the above instance B2.
    >>
    >>So instead of going into each cell, placing an "=" in front of the value
    >>and
    >>then putting an * B2 at the end of the value in each cell, I am trying to
    >>figure out how set up a macro and do it automatically.
    >>

    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1