+ Reply to Thread
Results 1 to 2 of 2

Multiply cells in range by corresponding factor

  1. #1
    tbargsta@earthlink.net
    Guest

    Multiply cells in range by corresponding factor

    I'm a beginner at writing VBA macros and I need some help. What I want
    to do is to provide the ability to select a range of cells in a
    spreadsheet then click on a command button that runs a macro that
    multiplies the content of each cell in the selected range by a
    corresponding factor identified in row 2 of each column.

    (Example) In row 2 the cells contain (A2)5,(B2)5 and (C2)10; Cells
    A4:C5 contain values (A4)1,(B4)2,(C4)3,(A5)2,(B5)3,(C5)1. I select
    range B4:C5. After running the macro the cells now contain
    (A4)1,(B4)10,(C4)30,(A5)2,(B5)15,(C5)10.

    If anyone could provide the code to perform this task I could use your
    help. Thanks


  2. #2
    Lonnie M.
    Guest

    Re: Multiply cells in range by corresponding factor

    Hi, try something like this in a standard module:

    Sub myCalc()
    Dim myCell As Range
    Dim C&
    For Each myCell In Selection
    If Application.WorksheetFunction.IsNumber(myCell.Value) Then
    C = myCell.Column
    myCell.Value = Cells(2, C) * myCell.Value
    End If
    Next
    End Sub

    HTH--Lonnie M.


+ 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