+ Reply to Thread
Results 1 to 5 of 5

Running Macro for entire column

  1. #1
    Registered User
    Join Date
    07-14-2014
    Location
    Ontario, Canada
    MS-Off Ver
    2007
    Posts
    3

    Running Macro for entire column

    I have the following Macro which I got to work how I wanted to for inventory, I would like it to be applied to the entire column instead of having to select each cell. Some cells will be empty and there is a header near the top of the worksheet to ignore. If not possible, being able to have it applied to a selection now, and then as I add more items I can run the macro for that item over time.

    Thanks

    ' The Auto_Open name forces this macro to run every time
    ' the workbook containing this macro is opened.

    Sub Auto_Open()
    ' Every time a cell's value is changed,
    ' the RunningTotal macro runs.
    Application.OnEntry = "RunningTotal"
    End Sub

    '----------------------------------------------------------
    ' This macro runs each time the value of a cell changes.
    ' It adds the current value of the cell to the value of the
    ' cell comment. Then it stores the new total in the cell comment.
    Sub RunningTotal()

    On Error GoTo errorhandler ' Skip cells that have no comment.

    With Application.Caller

    ' Checks to see if the cell is a running total by
    ' checking to see if the first 4 characters of the cell
    ' comment are "RT= ". NOTE: there is a space after the equal
    ' sign.
    If Left(.Comment.Text, 4) = "RT= " Then

    ' Change the cell's value to the new value in the cell
    ' plus the old total stored in the cell comment.
    RT = Right(.Comment.Text, Len(.Comment.Text) - 4) - .Value
    .Value = RT

    ' Store the new total in the cell note.
    .Comment.Text Text:="RT= " & RT
    End If
    End With

    Exit Sub ' Skip over the errorhandler routine.

    errorhandler: ' End the procedure if no comment in the cell.
    Exit Sub

    End Sub

    '--------------------------------------------------------------
    ' This macro sets up a cell to be a running total cell.
    Sub SetComment()
    With ActiveCell
    ' Set comment to indicate that a running total is present.
    ' If the ActiveCell is empty, multiplying by 1 will
    ' return a 0.
    .AddComment
    .Comment.Text Text:="RT= " & (ActiveCell * 1)
    End With
    End Sub

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Running Macro for entire column

    Hi, Pinnz,

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Registered User
    Join Date
    07-14-2014
    Location
    Ontario, Canada
    MS-Off Ver
    2007
    Posts
    3

    Re: Running Macro for entire column

    Sorry I have corrected it now
    Please Login or Register  to view this content.

  4. #4
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Running Macro for entire column

    Hi, Pinnz,

    you could have edited the original post instead of doing a new one.

    The macros you use are from the oldest of times - pre 97 when the Worksheet-Events where introduced. I wonder why anybody indicating to use Excel2007 still would work with these macros.

    Code goes behind the worksheet you want to monitor, this is for filling in the comments:
    Please Login or Register  to view this content.
    As you may have only one event of the given name you would have to use a different event for the change of comment text, maybe a double click:
    Please Login or Register  to view this content.
    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    07-14-2014
    Location
    Ontario, Canada
    MS-Off Ver
    2007
    Posts
    3

    Re: Running Macro for entire column

    Thanks for the reply, this is actually old code that I've brought out to use again. It's been years so I am rubbish at it now. I will try it out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro hiding entire row if value in certain column #N/A or zero
    By arkharova.s in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2014, 01:15 AM
  2. Macro to check Entire Column Q for 0 and stop macro
    By L2012 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-06-2012, 12:36 PM
  3. VBA Macro Replace Entire column
    By dwr0211 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 07-25-2011, 04:31 PM
  4. How do you delete entire column with Macro?
    By geng in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-09-2010, 09:26 PM
  5. HOW TO RUN MACRO ON ENTIRE COLUMN
    By -JEFF- in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-15-2005, 12:06 PM

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