+ Reply to Thread
Results 1 to 10 of 10

Automatic macro

  1. #1
    Registered User
    Join Date
    01-30-2016
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    17

    Automatic macro

    Hi all,

    I have a simple macro that I would like to start whenever the value in cell H13 or H14 is changed. I've searched online, but either I'm doing something wrong, or the given answers do not work.

    Anyone who knows how to get it going?

    This is the macro that should start whenever H13 or H14 is changed:

    Sub Hide()

    For i = 35 To 106
    If Cells(i, 8).Value = 0 Then
    Cells(i, 8).EntireRow.Hidden = True
    End If
    Next i

    For i = 35 To 106
    If Cells(i, 8).Value > 0 Then
    Cells(i, 8).EntireRow.Hidden = False
    End If
    Next i

    End Sub

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Automatic macro

    .
    .
    For starters, to comply with the FORUM rules, always put your code in the # brackets.

    Using this code :

    Please Login or Register  to view this content.
    I condensed your code a little. Instead of using two of the same, you can use one >= so long as other parts don't change.

    See how this works ....
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    01-30-2016
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    17

    Re: Automatic macro

    Thanks, but if I use your sheet, Excel hides all rows 35 to 106, whatever the value in column H of a row (for instance add 5 to H50). If you then go to H13 or H14, row 50 is being hidden, while it shouldn't.

  4. #4
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Automatic macro

    I've missed something in your request. I don't understand what you are asking.

  5. #5
    Registered User
    Join Date
    01-30-2016
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    17

    Re: Automatic macro

    Well,

    The goal of the macro is to hide all rows from 35 to 106 in which the value in column H is zero. That's why I had the Cells(i,8)-code, which worked. It did what it had to.

    Somehow your code no longer does that, as it hides all rows from 35 to 106, whatever the value in column H.

    So your code does work 'automatic', which is great, but somehow it lost the goal of the macro.

  6. #6
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Automatic macro

    If the value 0 (zero) is entered in Cell H13 or H14 ? Only those two cells ?

    If 0 (zero) shows up in H13 or H14 then rows 35 to 106 should be hidden ?

  7. #7
    Registered User
    Join Date
    01-30-2016
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    17

    Re: Automatic macro

    No, the value of H13 of H14 is irrelevant to determine what rows should be hidden. It is the value in the H-column that determines what rows should be hidden:
    for instance: if H36 is 0, then row 36 should be hidden. If H37 is 5, then row 37 should not be hidden, and so on.

    A change in H13 or H14 determine when the macro should be executed/started.

  8. #8
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Automatic macro

    Ok, I believe I understand what it is you are attempting.

    See if this works...

    Placing this code into the Sheet1 :

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by Logit; 12-21-2016 at 09:44 PM.

  9. #9
    Registered User
    Join Date
    01-30-2016
    Location
    Belgium
    MS-Off Ver
    Office 2013
    Posts
    17

    Re: Automatic macro

    Great, thank you very much. I changed the code a little to really do what I want:

    Please Login or Register  to view this content.
    The only thing is: it doesn't seem to work if I use this code in a new sheet. Is there something else I need to do to make it work in a new sheet, except paste this code in VBA?

    I'm trying to learn so I need to ask as few things here as possible ;-)

    Edit: Nvm, it does work. Forgot to save as an Excel-sheet with macro's. Stupid me ;-)
    Last edited by _Nebur_; 12-22-2016 at 03:27 PM.

  10. #10
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Automatic macro

    Glad to help. If your question is answered please mark this thread Solved.

    Merry Christmas !

+ 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. Automatic every 10 Minutes macro but another macro can be run
    By harrisj_ in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-21-2015, 10:38 AM
  2. [SOLVED] Macro construction and automatic triggering of a macro
    By Berean50 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-18-2013, 03:02 AM
  3. [SOLVED] How to make a macro automatic
    By Issacraj in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 07-15-2012, 02:15 AM
  4. Macro for automatic copy down?
    By Neil444 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-17-2012, 01:16 PM
  5. Automatic Macro
    By SteveF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-05-2010, 02:43 PM
  6. Automatic Filter Macro
    By Maxjohnson in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2006, 10:31 PM
  7. Automatic macro
    By ihr in forum Excel General
    Replies: 2
    Last Post: 01-26-2005, 06:31 AM

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