Show all, but leave the cursor where it is

A

Annette

I used the macro below to hide columns, but want to add code that says
unhide all columns and leave the cursor where it is before the below code is
run. How would I add that into this macro? (I don't want to use 'custom
view' because the cursor is left exactly where the view was saved)

Dim arr As Variant
Dim i As Long
arr = Array("d:d", "f:f", "h:h", "j:j")
For i = LBound(arr) To UBound(arr)
Columns(arr(i)).EntireColumn.Hidden = True
Next
 
J

JLGWhiz

I ran this code with the cursor in G3. It stayed in G3 during the hide and
unhide process.

Sub hidn()
Dim arr As Variant
Dim i As Long
arr = Array("d:d", "f:f", "h:h", "j:j")
For i = LBound(arr) To UBound(arr)
Columns(arr(i)).EntireColumn.Hidden = True
Next
'MsgBox "Check" 'For testing only
For i = LBound(arr) To UBound(arr)
Columns(arr(i)).EntireColumn.Hidden = False
Next
End Sub
 
J

JLGWhiz

In case you have more that the three columns you want to unhide.

Sub hidn()
Dim arr As Variant
Dim i As Long
arr = Array("d:d", "f:f", "h:h", "j:j")
For i = LBound(arr) To UBound(arr)
Columns(arr(i)).EntireColumn.Hidden = True
Next
'MsgBox "Check" 'For testing only
For Each c In Sheets(1).Columns
If c.Hidden = True Then
c.Hidden = False
End If
Next
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top