How to get multiple cells to multiply different figures

Shesmi130

New Member
Joined
Nov 1, 2017
Messages
7
I have used the formula below to get a specific set of cells to produce a multiplied figure, however it will only work for one row. Each time I change the details in the formula to include another row it deletes the info that was added for the previous row. Is there a way to use the formula on multiple rows that have different values? For example, I need C3:I3 to multiply by 10 but I need C5:I5 to multiply by 18.

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "H1:H10" '<== change to suit
Const SET_VALUE As Long = 23 '<== change to suit

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then

With Target

If IsNumeric(.Value) Then .Value = .Value * SET_VALUE
End With
End If

ws_exit:
Application.EnableEvents = True
End Sub
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Welcome to the Board!

Just add a second block that emulates the first, i.e.
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

    Const WS_RANGE1 As String = "C3:I3"
    Const SET_VALUE1 As Long = 10
    Const WS_RANGE2 As String = "C5:I5"
    Const SET_VALUE2 As Long = 18

    On Error GoTo ws_exit
    Application.EnableEvents = False

'   Check first range
    If Not Intersect(Target, Me.Range(WS_RANGE1)) Is Nothing Then
        With Target
            If IsNumeric(.Value) Then .Value = .Value * SET_VALUE1
        End With
    End If

'   Check second range
    If Not Intersect(Target, Me.Range(WS_RANGE2)) Is Nothing Then
        With Target
            If IsNumeric(.Value) Then .Value = .Value * SET_VALUE2
        End With
    End If

ws_exit:
    Application.EnableEvents = True
    
End Sub
 
Upvote 0
Thank you for the suggestion! I tried entering the info you provided but I received a syntax error. I then decided to omit the "check first range" and "check second range" phrases but it still didn't work.
 
Upvote 0
There are no syntax error in my code. I checked and ran it successfully.
Did you copy it "as-is", or try typing or changing anything.
 
Upvote 0
I copied from the code I had in already. Then I just added the number. 1,2,3 and so on. The syntax error said it was on the "check first range" phrase
 
Upvote 0
The problem is probably with the changes you made.
Please post your code that is returning the error, EXACTLY as you currently have it.
 
Upvote 0
After copying and pasting your work it worked fine. I Tgen tried to duplicate the wording ave adding a 3rd range. I'm getting the syntax error. Its highlighting the "Check third range" phrase. I'll see if I can post a pic.
 
Upvote 0
Scratch that last response. I realized I had left out the apostrophe. I've added that in and I'm no longer getting a syntax error, however, it's just not calculating.
 
Upvote 0
Ok! Scratch both of the last 2 responses! I finally got it to work properly!! Yay!! Now, on 3 of the fields the value is 1.5. This value is being rounded to the next whole number. Id's there a way to make it calculate at the 1.5?
 
Upvote 0
Hi! Can you help me in creating a drop down list that can select multiple options. I got a code that can select multiple options but it is separated with comma. My client wants it separate in different cell under the same column. Please I need some help with this. Thank you in advance.
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top