Array Worksheets

rach_oh

New Member
Joined
Aug 2, 2023
Messages
19
Office Version
  1. 2016
Platform
  1. Windows
I'm trying to look in every row in the same column in an array of spreadsheets. The module will run the sheets but not on the ones designated in the array. Not sure what I am missing...


VBA Code:
Dim ws As Worksheet
Dim Pwd As Variant
Dim UpdateView As Sheets
Set UpdateView = ActiveWorkbook.Sheets(Array("Golf Input", "Maintenance Input", "F&B Input", "G&A Input", "Summary", "Golf Summary", "Maintenance Summary", "F&B Summary", "G&A Summary"))
Pwd = InputBox("Enter password to protect all sheets", "PASSWORD REQUIRED")
If Pwd = "test123" Then

'Hide unnecessary rows
With UpdateView

For Each ws In UpdateView
LineStart = 6
ColumnNumber = 2
For i = LineStart To 250

If Cells(i, ColumnNumber).Value <> "Yes" Then
Cells(i, ColumnNumber).EntireRow.Hidden = True
Else
Cells(i, ColumnNumber).EntireRow.Hidden = False
End If
Next i
Next ws
End With
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
You are not referencing the cells, eg Cells(i, ColumnNumber), to the particular worksheet so vba will be looking at that cell on the active sheet only every time through the loop.
It needs to be .Cells(i, ColumnNumber)
Try something like this instead.
(I would also suggest indenting your code so that it is easier to identify where individual 'blocks' start and end)

VBA Code:
Dim LineStart As Long, ColumnNumber As Long, i As Long
Dim ws As Worksheet
Dim Pwd As Variant
Dim UpdateView As Sheets
Set UpdateView = ActiveWorkbook.Sheets(Array("Golf Input", "Maintenance Input", "F&B Input")) ', "G&A Input", "Summary", "Golf Summary", "Maintenance Summary", "F&B Summary", "G&A Summary"))
Pwd = InputBox("Enter password to protect all sheets", "PASSWORD REQUIRED")
If Pwd = "test123" Then

  'Hide unnecessary rows
  For Each ws In UpdateView
    With ws
      LineStart = 6
      ColumnNumber = 2
      For i = LineStart To 250
        .Rows(i).Hidden = .Cells(i, ColumnNumber).Value <> "Yes"
      Next i
    End With
  Next ws
End If
 
Upvote 0

Forum statistics

Threads
1,215,353
Messages
6,124,458
Members
449,161
Latest member
NHOJ

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