code not doing what I intended

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,342
Office Version
  1. 365
Platform
  1. Windows
Why is this not clearing the rows and why is it hiding column C?

I am running it from a button on a different sheet

Code:
Private Sub CommandButton2_Click()

On Error Resume Next

   Sheets("ItemTemplate").Activate
    Rows("2:200").Clear
    
    Range("A1").Value = "UserId"
    Range("B1").Value = "ParentItemID"
    Range("C1").Value = "ItemID"
    Range("d1").Value = "ItemDescription"
    Range("A2").Select
    
    Columns("E:E").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.EntireColumn.Hidden = True
    Range("D14").Select

End Sub
 

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)
What happens if you remove this line
Code:
On Error Resume Next
 
Upvote 0
What happens if you remove this line
Code:
On Error Resume Next

I don’t. Think that’s the problem. Even if I take it out it doesn’t clear and it hides C
 
Upvote 0
Does this work?
Code:
Private Sub CommandButton2_Click()

    With Sheets("ItemTemplate")
        .Rows("2:200").Clear
        .Range("A1:D1").Value = Array("UserId", "ParentItemID", "ItemID", "ItemDescription")
        .Range(.Columns("E:E"), .Columns("E:E").End(xlToRight)).EntireColumn.Hidden = True
        applicaton.Goto .Range("D14"), True
    End With

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,619
Members
449,238
Latest member
wcbyers

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