VBA - Some actions happening on wrong sheet

jg65801

New Member
Joined
May 25, 2013
Messages
3
The code i have is to copy a template, ask the user for the sheet name and some data.

All this works fine however the next part of the code is to hide some rows and this always happens on the template rather than the new sheet.

Does anyone see what the issue is with the code as to why this is happening?

Code:
Public Sub CopySheetAndRename()    Dim newName As String
 
    On Error Resume Next
    newName = InputBox("Enter the sheet name")
    Data = InputBox("Enter Data")
 
    If newName <> "" Then
        Sheets("Template").Copy After:=Worksheets(Sheets.Count)
        On Error Resume Next
        ActiveSheet.Name = newName
        
        Worksheets(newName).Range("C3") = newName
        Worksheets(newName).Range("C5") = Data
    Worksheets(newName).Activate
    
    End If
    
Application.ScreenUpdating = False
Application.Calculation = xlManual
 
For Each c In Worksheets(newName).Range("D5:D53")
    If c.Value = "x" Then Rows(c.Row).Hidden = True
Next
 
Application.Calculation = xlAutomatic
Application.ScreenUpdating = True


End Sub
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
How about
Code:
For Each c In Worksheets(newName).Range("D5:D53")
    If c.Value = "x" Then c.EntireRow.Hidden = True
Next
 
Upvote 0
Cross posted https://www.excelforum.com/excel-pr...4-vba-running-on-wrong-sheet.html#post5154301

While we do not prohibit Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules).
This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,215
Members
452,618
Latest member
Tam84

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