troubleshooting Question

vba script not selecting the right tab

Avatar of rjef
rjefFlag for United States of America asked on
VBAMicrosoft ExcelMicrosoft Office
8 Comments1 Solution15 ViewsLast Modified:
any idea why this vba script is not putting the correct company name in the correct tab
attached is the excel sheet.  Column 'E' should be the company name, same as the tab

here is the script
Sub DailyReport()
    Dim cust(100) As String
cust(1) = "Company1"
cust(2) = "Company2"
cust(3) = "Company3"
cust(4) = "Company4"
cust(5) = "Company5"
cust(6) = "Company6"
cust(7) = "Company7"
cust(8) = "Company8"
cust(9) = "Company9"
cust(10) = "Company10"
cust(11) = "Company11"
cust(12) = "Company12"
cust(13) = "Company13"
xxx = 13

For gg = 1 To xxx
Set Rng = Nothing
    stuff = Cells(2, 1)
        If stuff <> 0 Then
            With ActiveSheet
                'Getting the last filled in row number for a column. Can be any column (avoid columns that will have blanks), just want to know how far down the list goes.
                DataEnd = .Range("A" & .Rows.Count).End(xlUp).Row
                    MsgBox DataEnd
                    If DataEnd <> 1 Then
                     '   On Error Resume Next
                            .Range("A:AV").AutoFilter Field:=5, Criteria1:=cust(gg)
                            Set Rng = .Range("E2:E" & DataEnd).SpecialCells(xlCellTypeVisible).EntireRow
                                Rng.Copy Sheets(cust(gg)).Range("A2")
                     '       On Error GoTo 0
                    End If
            End With
        End If
Next gg

Open in new window

Log in to continue reading
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform for $9.99/mo
View membership options
Unlock 1 Answer and 8 Comments.
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
The Value of Experts Exchange in My Daily IT Life

Experts Exchange (EE) has become my company's go-to resource to get answers. I've used EE to make decisions, solve problems and even save customers. OutagesIO has been a challenging project and... Keep reading >>


Owner of Outages.IO
Phoenix, Arizona, United States
Member Since 2016
Join a full scale community that combines the best parts of other tools into one platform.
Unlock 1 Answer and 8 Comments.
View membership options
“All of life is about relationships, and EE has made a virtual community a real community. It lifts everyone's boat.”
William Peck

Member since 2004