ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Show all, but leave the cursor where it is (https://www.excelbanter.com/excel-programming/408418-show-all-but-leave-cursor-where.html)

Annette[_3_]

Show all, but leave the cursor where it is
 
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



JLGWhiz

Show all, but leave the cursor where it is
 
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


"Annette" wrote:

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




JLGWhiz

Show all, but leave the cursor where it is
 
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

"Annette" wrote:

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





All times are GMT +1. The time now is 06:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com