Link to home
Start Free TrialLog in
Avatar of BBlu
BBluFlag for United States of America

asked on

Working with Range VBA

I'm new to VBA, trying to learn as quickly as I can.  I am trying to do what I think is a simple task, but it's not working.  I simply want to select a group of cells, then change the sign (multiply by -1).  I'm not sure why.  Could someone help?

 
Sub Changesign(ByVal numsToChange As Range)
    Dim checkRange As Range
    For Each checkRange In numsToChange
    checkRange = checkRange * -1
End Sub

Open in new window

Avatar of wchh
wchh

Add
Next checkrange
after checkRange = checkRange * -1
ASKER CERTIFIED SOLUTION
Avatar of wchh
wchh

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of Girard Tabañag, MBA, MIT, MACS CP
Girard Tabañag, MBA, MIT, MACS CP
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BBlu

ASKER

Thank you all.  I'm not sure what I'm doing wrong here.  I've edited mine according to the first response and added another just for testing and learning.  But neither appears in my macros list when I try to run them.  See attached.


ScreenShot-ChangeSign1.png
Avatar of BBlu

ASKER

User generated image
The macros list will not show macros that take a parameter as yours does.  You need to create a macro that has no parameter and calls yours, like
Sub TestChange()
    Call ChangeSign(Selection)
End Sub

Open in new window

Avatar of BBlu

ASKER

Thank you all
Avatar of BBlu

ASKER

As usual, Awesome!  Thanks to you all.