Store data in array
Option Explicit ' First line in module!
Sub ArrayStore_R1()
Dim rng As Range
Dim hCol() As Long
Dim hColI As Long
'Declare all variables.
Dim colNum As Long
Dim N As Long
'1. Find last column with data
Set rng = Cells.Find(What:="*", After:=Range("IV65536"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)
colNum = rng.Column + 1
'2. Store Hidden Columns
ReDim hCol(1 To colNum)
For hColI = 1 To colNum
If Columns(hColI).EntireColumn.Hidden = True Then
N = N + 1
hCol(N) = hColI
End If
Next
ReDim Preserve hCol(1 To N)
'Use column A to display the array contents...
Range("A1", Cells(N, 1)).Value = Application.Transpose(hCol)
End Sub
--
Jim Cone
Portland, Oregon USA
"jfcby"
wrote in message
Hello,
I have a workbook with hidden rows. How can I modify the following
code to store the hidden columns in an array?
<CODE BEGIN
Sub ArrayStore()
Dim i As Long 'Integer
Dim rng As Range
'1. Find last column with data
Set rng = Cells.Find(What:="*", After:=Range("IV65536"), _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious)
colnum = rng.Column + 1
'2. Store Hidden Columns
Dim hCol()
Dim hColI As Integer
For hColI = 1 To colnum
If Columns(hColI).EntireColumn.Hidden = 0 Then hCol() =
Array(hColI & ",")
Next
For i = LBound(hCol) To UBound(hCol)
MsgBox i & ", " & hCol(i)
Next
End Sub
<CODE END
Thank you for your help,
jfcby
|