Wednesday, May 1, 2019

excel - convert cells in to an array of variant

I need to store some cell values into an array of variants. (I'm using this array in a for each loop, so it has to be variant) The following code gives a type mismatch error. Could someone please show me how to do it? Thanks in advance.



Public Sub MainSub()

Dim ws_names() As Variant
ws_names = Worksheets("Lookup").Range("K3:K5")
ShowCertainWorksheets ws_names
End Sub

Public Sub ShowCertainWorksheets(ByVal ws_names As Variant)
Dim ws_name As Variant
For Each ws_name In ws_names
ThisWorkbook.Worksheets(ws_name).Visible = True
Next ws_name

End Sub


Worksheets("Lookup").Range("K3:K5") contains only worksheet names that exist in the file so there's no problem there...

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...