VBA to hide and unhide rows

Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention   -  
danielc0 Posted messages 2191 Registration date   Status Member Last intervention   -

Hello,

I would like to get help with VBA code that would hide and unhide rows in Excel.

See attached file.

The idea is that for each category (Receipts, Expenses and subcategories of expenses), when the user clicks on the down arrow:

- this unhides the detail rows of the category, but only the rows that are not in column E zero or column G zero.

- hides the down arrow.

And when the user clicks on the up arrow:

- this hides the detail rows of the category

- hides the up arrow

- shows the down arrow

- shows the up arrow

I have some knowledge of VBA (beginner) but I don’t know how to approach this.

2 answers

  1. NonoM45 Posted messages 1020 Registration date   Status Member Last intervention   5
     

    Hello Thibault,

    I’ve drafted the recipes; you’ll just need to do the same for the rest

    https://www.transfernow.net/dl/20260702Mt7AgUg5/dHq5r4Ps

    Cheers

    0
    1. Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention  
       

      Thank you.

      Is it possible to have some explanations with each code snippet so I can grasp it and try to reproduce it for the rest?

      0
  2. danielc0 Posted messages 2191 Registration date   Status Member Last intervention   287
     

    Hello,

    By slightly modifying the sheet, to simplify the VBA code

    https://www.swisstransfer.com/d/127480ef-6685-4330-84c7-2cd9f3887591

    Daniel


    0
    1. Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention  
       

      Thank you.

      Haa it's not bad either. The code seems simpler.

      Is it possible to have a few explanations for each block of code so that I can get the hang of it and try to reproduce it?

      Perhaps a false impression on my part, but I feel that if from 0€ we move to an amount in column G or I... the row remains hidden anyway... That VBA doesn’t take into account that there is now an amount and that the row should not be hidden.

      No?

      Stupid question... How to redisplay an image when it has been made invisible by the VBA code?

      0
      1. danielc0 Posted messages 2191 Registration date   Status Member Last intervention   287 > Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention  
         

        I added the columns that contain the arrows. I corrected (I think) the amounts to 0. Please check.

        I will add comments in the code to explain it when I have corrected any possible errors.

        I don’t know how to make an object visible other than by macro. Select the arrow and run:

        Sub test() Selection.Visible = True End Sub 

        https://www.swisstransfer.com/d/ea292767-8234-498e-9f22-7302fbc86ba1

        Daniel

        1
      2. Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention   > danielc0 Posted messages 2191 Registration date   Status Member Last intervention  
         

        Thank you, that indeed resolved it.

        I will try to rearrange in my original file as you did, and increment the VBA.

        0
      3. danielc0 Posted messages 2191 Registration date   Status Member Last intervention   287 > Boyscout_27 Posted messages 18 Registration date   Status Member Last intervention  
         

        Be mindful of the arrow positions. The top-left angle must be in columns A, B, D, or E and on the same row as the data to display/hide (38, 45, 56...).

        Daniel

        0