If else vba

Last Edited By Krjb Donovan
Last Updated: Mar 05, 2014 09:42 PM GMT

Question

I am trying to make a simple if else statement in VBA. I just want to select a cell and if the cell above it is hidden then have it display "H1" and if the cell above it is not hidden then have it display "H2". It finally displays H1 if the cell above is hidden but I cannot get the else part to work right it will not display H2 when it needs to. There are no errors or anythign that pop up when run. My code is as follows:


With Range("B5, B9, B13, B17, B21, B25, B29, B33, B37, B41, B45, B49, B53, B57, B61, B65, B69, B73, B77, B81, B85, B89, B93, B97, B101")

       .Select
           For Each Cell In Range("B5, B9, B13, B17, B21, B25, B29, B33, B37, B41, B45, B49, B53, B57, B61, B65, B69, B73, B77, B81, B85, B89, B93, B97, B101")
               If Cells.Offset(-1, 0).Hidden = True Then
                   Cell.Value = "H1"
               ElseIf Cells.Offset(-1, 0).Hidden = False Then
                   Cell.Value = "H2"
               End If
           
           Next Cell

Answer

Jeff

Sorry I am not a VBA expert so I can't really help you with your question. Your code looks okay to me, and of course it isn't. I suggest you reask the question of another allexperts person and ck the resumes for one who is VBA expert. I am sure you can get a good answer,

Sorry I couldn't be of more help.

Advertisement

©2024 eLuminary LLC. All rights reserved.