Hi, I need help with this error please. One of my ex colleagues has left and he created a spreadsheet built with VB/Marcros. Basically there is 7 groups and it splits them all and creates separate excel spreadsheets when clicking the macro button. I had been using this all year but for some reason it brings up this error and highlighting this code:
If Sheets("Shop Tables").Cells(a, 5).Value = FltVal And Sheets("Shop Tables").Cells(a, 7).Value > 0 Then
Full code for marcro is this:
Sub GroupSplitter()
Dim fsht As Boolean
WeekNo = Sheets("Front").Range("WeekNo").Value
ThisBook = ActiveWorkbook.Name
FN = Sheets("Front").Range("FNAME").Value
fsht = False
For grpNo = 21 To 31
Sheets("Front").Select
If Not (IsEmpty(Sheets("Front").Cells(grpNo, 2).Value)) Then
' Filter Value - Group/Regional/BDE
FltVal = Sheets("Front").Cells(grpNo, 2).Value
' ######### Loop this section #########
For aaa = 3 To 5
Workbooks(ThisBook).Activate
If Sheets("Front").Cells(grpNo, aaa).Value = "x" Then
Sheets("Front").Range("SortBy").Value = Sheets("Front").Cells(9, aaa).Value
' Columns to sort by (% / Parcels)
ColSort1 = Sheets("Front").Range("ColSort1").Value
ColSort2 = Sheets("Front").Range("ColSort2").Value
' Sort Tables
ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Add Key:= _
Range(ColSort1 & "4:" & ColSort1 & "10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort.SortFields.Add Key:= _
Range(ColSort2 & "4:" & ColSort2 & "10000"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
:=xlSortNormal
With ActiveWorkbook.Worksheets("Shop Tables").AutoFilter.Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
' Create new Sheet and copy Header
Dim WS As Worksheet
Set WS = Sheets.Add
WS.Name = "Data"
Sheets("Shop Tables").Select
Sheets("Shop Tables").Range(Cells(1, 1), Cells(3, 6)).Copy Destination:=Sheets("Data").Cells(1, 1) ' Account Details
Sheets("Shop Tables").Range(Cells(1, 7), Cells(3, 9)).Copy Destination:=Sheets("Data").Cells(1, 7) '
Sheets("Shop Tables").Range(Cells(1, 10), Cells(3, 12)).Copy Destination:=Sheets("Data").Cells(1, 10)
Sheets("Shop Tables").Range(Cells(1, 13), Cells(3, 15)).Copy Destination:=Sheets("Data").Cells(1, 13)
a = 4
c = 4
sID = Sheets("Shop Tables").Cells(a, 1).Value
Do Until IsEmpty(sID)
If Sheets("Shop Tables").Cells(a, 5).Value = FltVal And Sheets("Shop Tables").Cells(a, 7).Value > 0 Then
Sheets("Shop Tables").Range(Cells(a, 1), Cells(a, 6)).Copy Destination:=Sheets("Data").Cells(c, 1)
Sheets("Shop Tables").Range(Cells(a, 7), Cells(a, 9)).Copy Destination:=Sheets("Data").Cells(c, 7)
Sheets("Shop Tables").Range(Cells(a, 10), Cells(a, 12)).Copy Destination:=Sheets("Data").Cells(c, 10)
Sheets("Shop Tables").Range(Cells(a, 13), Cells(a, 15)).Copy Destination:=Sheets("Data").Cells(c, 13)
c = c + 1
End If
sID = Sheets("Shop Tables").Cells(a, 1).Value
a = a + 1
Loop
Sheets("Data").Select
ActiveWindow.DisplayGridlines = False
Rows("2:2").RowHeight = 36
Rows("3:3").RowHeight = 36
Cells.Select
Cells.EntireColumn.AutoFit
Range("A3").Select
Sheets("Data").Select
' Delete cols if Depot-Shop or Shop-Customer
If aaa = 4 Then Columns("J:O").Delete
If aaa = 5 Then
Columns("G:I").Delete
Columns("J:L").Delete
End If
If aaa = 4 Or aaa = 5 Then
Rows("1:2").Delete
End If
If fsht Then
Sheets("Data").Move After:=Workbooks(NewBk).Sheets(Workbooks(NewBk).Sheets.Count)
Else: Sheets("Data").Move
End If
ActiveSheet.Name = Workbooks(ThisBook).Sheets("Front").Range("SortBy").Value
NewBk = "Week " & WeekNo & " - Compliance Report - " & FltVal & ".xlsx"
If fsht = False Then ActiveWorkbook.SaveAs Filename:=FN & NewBk
fsht = True
End If
Next aaa
' ######### END - Loop this section #########
End If
Workbooks(NewBk).Save
Workbooks(NewBk).Close
fsht = False
Next grpNo
End Sub
Bookmarks