+ Reply to Thread
Results 1 to 4 of 4

Performing an action on a selection (ActiveCell?)

  1. #1
    Registered User
    Join Date
    08-10-2009
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Performing an action on a selection (ActiveCell?)

    Hello everyone,

    I'm a bit of a beginner in excel macros and I have a small problem. I would like to perform an action (multiply by (-1) to get opposite numbers) on an "active selection".

    Its easy to make a macro to do this on a single active cell:
    ActiveCell.Value = ActiveCell.Value * (-1)

    ....But what I want to do is perform this same action on all the cells I have selected. Is there some function to do this? I have tried searching around the board and on the internet but havent found anything to help me out with this specific thing.

    I have attached a picture to show what im trying to do. The macro I have written only does the action on the 1st cell instead of all the selected ones.

    What I have atm is:

    Please Login or Register  to view this content.

    Thanks in advance,
    Glooms
    Attached Images Attached Images
    Last edited by dominicb; 08-10-2009 at 03:46 AM.

  2. #2
    Forum Expert dominicb's Avatar
    Join Date
    01-25-2005
    Location
    Lancashire, England
    MS-Off Ver
    MS Office 2000, 2003, 2007 & 2016 365
    Posts
    4,867

    Smile Re: Performing an action on a selection (ActiveCell?)

    Good morning Glooms

    ...and welcome to the forum!!
    Quote Originally Posted by Glooms View Post
    ....But what I want to do is perform this same action on all the cells I have selected. Is there some function to do this? I have tried searching around the board and on the internet but havent found anything to help me out with this specific thing.
    The code shown below should help you. Notice how you don't actually have to select the cell to work on it - just specifying it will be necessary. In the instance below it is part of the range variable.

    Please Login or Register  to view this content.
    Pleasew try and remember to wrap any code you have posted in the code tags (use the # button) next timne you post.

    HTH

    DominicB
    Please familiarise yourself with the rules before posting. You can find them here.

  3. #3
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Performing an action on a selection (ActiveCell?)

    try
    Please Login or Register  to view this content.
    you could also assign this to a shortcut key for ease of use

    hope this helps.
    Last edited by D_Rennie; 08-10-2009 at 03:51 AM. Reason: beaten to it

  4. #4
    Registered User
    Join Date
    08-10-2009
    Location
    Finland
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: Performing an action on a selection (ActiveCell?)

    Hello,

    Thanks a lot, that exactly does the trick

    Will remember about the codewrapping next time I post aswell.

    Thanks again,
    Glooms

+ 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