1004 - method of range class error

rickblunt

Well-known Member
Joined
Feb 18, 2008
Messages
609
Office Version
  1. 2019
Platform
  1. Windows
Hello, I have another head scratcher for you (well for me anyway - lol) I am using the following code to transfer some data and it works perfectly...

VBA Code:
Sub EmergencyShowerReport()

    Dim rng As Range
    
    With Sheets("Device List")
        Set rng = .Range("A1:H" & .Range("A" & Rows.Count).End(xlUp).Row)
    End With
    With rng
        .AutoFilter Field:=1, Criteria1:="Emergency Shower"
        .SpecialCells(xlCellTypeVisible).Copy
        Sheets("Emergency Shower Report").Range("A1").PasteSpecial xlPasteValuesAndNumberFormats
        Sheets("Emergency Shower Report").Cells.EntireColumn.AutoFit
    End With
    
    Call ShowAll
           
       Sheets("Emergency Shower Report").Range("M1").Select
        
End Sub

But when I use this code to call it I get an 1004 error at the "Sheets("Emergency Shower Report").Range("M1").Select" syntax

VBA Code:
Private Sub EsReportButton_Click()

    Dim Answer As Integer

    Answer = MsgBox("Would you like to create the Emergency Shower Report now?", vbYesNo + vbQuestion, "Report Manager")
               
        If Answer = vbYes Then Call EmergencyShowerReport
    
End Sub

I do not understand why calling the sub is creating an error I really appreciate any insights on this - thanks
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hello, I have another head scratcher for you (well for me anyway - lol) I am using the following code to transfer some data and it works perfectly...
...
But when I use this code to call it I get an 1004 error at the "Sheets("Emergency Shower Report").Range("M1").Select" syntax

VBA Code:
Private Sub EsReportButton_Click()

    Dim Answer As Integer

    Answer = MsgBox("Would you like to create the Emergency Shower Report now?", vbYesNo + vbQuestion, "Report Manager")
              
        If Answer = vbYes Then Call EmergencyShowerReport
   
End Sub

I do not understand why calling the sub is creating an error I really appreciate any insights on this - thanks
The problem is with that last bit of code.

'Answer' is going to return an integer result. 7 will be returned if 'No' is selected and 6 will be returned if 'Yes' is selected. So when you check for 'vbYes', that is not going to happen.

VBA Code:
    Dim Answer As Integer
'
    Answer = MsgBox("Would you like to create the Emergency Shower Report now?", vbYesNo + vbQuestion, "Report Manager")
'
    If Answer = 7 Then
        MsgBox "No was selected"
    ElseIf Answer = 6 Then
        MsgBox "Yes was selected"
''        Call EmergencyShowerReport
    End If

So you may want to change:

VBA Code:
        If Answer = vbYes Then Call EmergencyShowerReport

to:

VBA Code:
        If Answer = 6 Then Call EmergencyShowerReport
 
Upvote 0
oh boy - that went over my head, I think I do understand what you are saying about having to answer both sides of the equation, but I do not understand the 6 and the 7. Is that one of those coding syntaxes that I see a lot? I am sorry for my ignorance, I have learned so much from all of you but I still have so much more to learn....
 
Last edited:
Upvote 0
This line:
Sheets("Emergency Shower Report").Range("M1").Select
cannot be executed unless the sheet with tab name "Emergency Shower Report" is the activesheet when the line is executed. Does the sub ShowAll leave that sheet active when it completes?
 
Upvote 0
Solution
Bingo! that's it - (sound of my forehead hitting my desk) the ShowAll is still focused on that sheet. I should have caught that - thank you once again
 
Upvote 0
Bingo! that's it - (sound of my forehead hitting my desk) the ShowAll is still focused on that sheet. I should have caught that - thank you once again
You are welcome - thanks for the reply.
 
Upvote 0
oh boy - that went over my head, I think I do understand what you are saying about having to answer both sides of the equation, but I do not understand the 6 and the 7. Is that one of those coding syntaxes that I see a lot? I am sorry for my ignorance, I have learned so much from all of you but I still have so much more to learn....
Sorry for any confusion I have caused, it appears that the integer and text values are interchangeable.
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,387
Members
448,957
Latest member
Hat4Life

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