If and ELseIF

imback2nite

Board Regular
Joined
Oct 30, 2004
Messages
211
Office Version
  1. 2003 or older
Platform
  1. Windows
I've written this and don't know what is going wrong.
Rich (BB code):
Private Sub CommandButton3_Click()
        If Range("3:2544").EntireRow.Hidden = False Then
        MsgBox ("Select Which Week To Update Names")
            Exit Sub
       ElseIf Range("4:6").EntireRow.Hidden = False Then
            Range("B8:B47").ClearContents
            Worksheets("Names").Range("B2:B41").Copy
            Range("B8").PasteSpecial Paste:=xlPasteValues
        ElseIf Range("51:54").EntireRow.Hidden = False Then
            Range("B56:B95").ClearContents
            Worksheets("Names").Range("B2:B41").Copy
            Range("B56").PasteSpecial Paste:=xlPasteValues
       ElseIf Range("99:102").EntireRow.Hidden = False Then
            Range("B104:B143").ClearContents
            Worksheets("Names").Range("B2:B41").Copy
            Range("B104").PasteSpecial Paste:=xlPasteValues
       ElseIf Range("147:150").EntireRow.Hidden = False Then
            Range("B152:B191").ClearContents
            Worksheets("Names").Range("B2:B41").Copy
            Range("B152").PasteSpecial Paste:=xlPasteValues
        End If
            Application.CutCopyMode = False
        Range("B1").Select
    Application.ScreenUpdating = True
End Sub
It all works except for the
Rich (BB code):
       ElseIf Range("4:6").EntireRow.Hidden = False Then
            Range("B8:B47").ClearContents
            Worksheets("Names").Range("B2:B41").Copy
            Range("B8").PasteSpecial Paste:=xlPasteValues
The rest of the ElseIf's work fine. I tried deleting the code below and it works fine but I do need it. Any help wound be appreciated.
Rich (BB code):
 If Range("3:2544").EntireRow.Hidden = False Then
        MsgBox ("Select Which Week To Update Names")
            Exit Sub
[/CODE] Because the code works fine without it.
 
Can I just confirm that you understand that ElseIf statements are alternatives. By that I mean when the code reaches an ElseIf that is True then it executes that section of code and from there goes straight to End If, bypassing all the ElseIfs that follow.
Yes. That's why I find it odd that with rows ("3:6") Unhidden, excel will not work. Yet the other ElseIf statements are unimpeded. With the rows ("3:6") unhidden it should stop there and complete till the next ElseIf.
 
Upvote 0

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Can you share your workbook using Dropbox, Google drive or some other sharing platform. You will need to allow access to anyone with the link.
 
Upvote 0
How are you kicking off the macro ? When I run it dirrectly it seems to do what it is intended to do.

1704779471876.png
 
Upvote 0
How are you kicking off the macro ? When I run it dirrectly it seems to do what it is intended to do.

View attachment 104643
Let's see. I run it from the TOKES page. I select the Input Names button and the 'Names' field is populated from the 'Names' page. It works for all the dates but from 12/31/23 to 01/06/24. When that filed is brought up I get the hiccup. The Select Which Week To Update Names MsgBox appears. It's not supposed to do that. Also, on the Dates Form you can select to see all weeks. If you then select the 'Input Names' button the names will repopulate the 12/31/23 to 1/6/24 field. It's not supposed to populate anything till only one weeks field is present. Not all of them. It's really a mess.
 
Upvote 0
I am confused, your buttons on the sheet TOKES appear to be Pictures and not buttons and don't seem to link to the macros you are running.
Is Input Names in your original spreadsheet an Active X button and linked to CommandButton3_Click() ?
 
Upvote 0
I am confused, your buttons on the sheet TOKES appear to be Pictures and not buttons and don't seem to link to the macros you are running.
Is Input Names in your original spreadsheet an Active X button and linked to CommandButton3_Click() ?
Yes. They are connected to buttons. I used the link I sent you and what I got really is a terrible representation.
 
Upvote 0
I am confused, your buttons on the sheet TOKES appear to be Pictures and not buttons and don't seem to link to the macros you are running.
Is Input Names in your original spreadsheet an Active X button and linked to CommandButton3_Click() ?
Yes. The Google Sheets is a poor download representation. You would have to see the worksheet. Using F8 should have bypassed the first IF statement.
 
Upvote 0
Yes. The Google Sheets is a poor download representation. You would have to see the worksheet. Using F8 should have bypassed the first IF statement.
I'm really not sure how but this seemed to have fixed it. 🤷‍♂️ Instead of ("3:2544") I put ("2:2544"). I wish you could see it and explain it to me. I say fixed but I don't think so. It just seems to work.
Rich (BB code):
        If Range("2:2544").EntireRow.Hidden = False Then
        MsgBox ("Select Which Week To Update Names")
        Exit Sub
        End If
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top