PDA

View Full Version : Ignore Hidden Sheets in vlookup macro



agnesz
04-23-2009, 12:40 PM
The following macro worked for me when the "Lookup Report" didn't have hidden sheets, however it turns out that it will always have the first tab and the last two tabs hidden. These cannot be included in the vlookup macro because it errors out. How can I make it work? I'm attaching the files.
THANKS A MILLION!

Option Explicit
Sub Macro2()
Dim wsReport As Worksheet
Dim wbSource As Workbook
Dim Shts As Long
Dim ShName As String
Dim wbName As String
Dim i As Long
Dim Rws As Long
Set wsReport = ActiveSheet

MsgBox "Select LocSum Report to link to"
Application.Dialogs(xlDialogOpen).Show ActiveWorkbook.Path
Set wbSource = ActiveWorkbook
wbName = wbSource.Name
Shts = wbSource.Sheets.Count
With wsReport
Rws = .Cells(Rows.Count, 15).End(xlUp).Row
.Activate
For i = 3 To Shts
.Range("P2:u" & Rws).Copy .Cells(2, 16 + (6 * (i - 2)))
ShName = wbSource.Sheets(i).Name
.Cells(2, 17 + (6 * (i - 2))) = ShName
.Cells(4, 18 + (6 * (i - 2))) = Split(ShName)(0)
.Cells(7, 16 + (6 * (i - 2))).FormulaR1C1 = "=VLOOKUP(RC3,'[" & wbName & "]" & ShName & "'!R14C7:R268C55,7,FALSE)"
.Cells(7, 17 + (6 * (i - 2))).FormulaR1C1 = "=VLOOKUP(RC3,'[" & wbName & "]" & ShName & "'!R14C7:R268C55,8,FALSE)"
.Cells(7, 18 + (6 * (i - 2))).FormulaR1C1 = "=VLOOKUP(RC3,'[" & wbName & "]" & ShName & "'!R14C7:R268C55,9,FALSE)"
With .Cells(7, 16 + (6 * (i - 2))).Resize(Rws - 6, 3)
.FillDown
.Borders(xlInsideHorizontal).LineStyle = xlNone
End With
Next
End With
End Sub

mdmackillop
04-23-2009, 01:06 PM
One of your files has protected code

For i = 3 To Shts
If Sheets(i).Visible = True then