willow1985
Well-known Member
- Joined
- Jul 24, 2019
- Messages
- 929
- Office Version
- 365
- Platform
- Windows
Hello,
I am looking for help on the below code. This code used to work on my spreadsheet but now it gives me a Runtime error 91 on line:
For Each cell In ws.Columns(1).Cells
This part of the code is not my own, I found this method online on how to select the first blank cell in column 1 in a table (Table name = PPAP) but now it does not seem to be working.
Any help would be greatly appreciated.
I am looking for help on the below code. This code used to work on my spreadsheet but now it gives me a Runtime error 91 on line:
For Each cell In ws.Columns(1).Cells
This part of the code is not my own, I found this method online on how to select the first blank cell in column 1 in a table (Table name = PPAP) but now it does not seem to be working.
Any help would be greatly appreciated.
VBA Code:
Sub PPAPData()
'
' PPAPData Macro
'
Dim PPD As String
Dim PPN As String
PPD = Workbooks("Eng_QA Dashboard").Sheets("Graph Data").Range("B38").Value
PPN = Workbooks("Eng_QA Dashboard").Sheets("Graph Data").Range("B39").Value
Sheets("PPAPs").Select
ActiveSheet.ListObjects("PPAP").Resize Range("$A$1:$O$2")
Rows("3:1000").Select
Selection.ClearContents
Range("A2").Select
ActiveCell.Range("PPAP[[#Headers],[Ppap Identifier]:[Comments]]").Select
Selection.ClearContents
Workbooks.Open PPD
'Grab PPAP Data
Windows(PPN).Activate
Sheets("PPAPs").Select
For Each lo In ActiveSheet.ListObjects
lo.AutoFilter.ShowAllData
Next lo
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Cells.EntireColumn.Hidden = False
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=5, Criteria1:=11, _
Operator:=11, Criteria2:=0, SubField:=0
If ActiveSheet.ListObjects("PPAP").Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
GoTo NextPP
End If
Range("A2").Select
ActiveSheet.ListObjects("PPAP").DataBodyRange.Columns("A:G").Select
Selection.SpecialCells(xlCellTypeVisible).Copy
Windows("Eng_QA Dashboard.xlsm").Activate
Sheets("PPAPs").Select
Dim ws As Worksheet
Set ws = ActiveSheet
For Each cell In ws.Columns(1).Cells 'the line that is giving me the error
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
NextPP:
Windows(PPN).Activate
Sheets("PPAPs").Select
For Each lo In ActiveSheet.ListObjects
lo.AutoFilter.ShowAllData
Next lo
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Cells.EntireColumn.Hidden = False
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=5, Criteria1:=10, _
Operator:=11, Criteria2:=0, SubField:=0
If ActiveSheet.ListObjects("PPAP").Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
GoTo NextPP2
End If
Range("A1").Select
ActiveSheet.ListObjects("PPAP").DataBodyRange.Columns("A:G").Select
Selection.SpecialCells(xlCellTypeVisible).Copy
Windows("Eng_QA Dashboard.xlsm").Activate
Sheets("PPAPs").Select
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
NextPP2:
Windows(PPN).Activate
Sheets("PPAPs").Select
For Each lo In ActiveSheet.ListObjects
lo.AutoFilter.ShowAllData
Next lo
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Cells.EntireColumn.Hidden = False
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=5, Criteria1:="="
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=4, Criteria1:=11, _
Operator:=11, Criteria2:=0, SubField:=0
If ActiveSheet.ListObjects("PPAP").Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
GoTo NextPP3
End If
Range("A1").Select
ActiveSheet.ListObjects("PPAP").DataBodyRange.Columns("A:G").Select
Selection.SpecialCells(xlCellTypeVisible).Copy
Windows("Eng_QA Dashboard.xlsm").Activate
Sheets("PPAPs").Select
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
NextPP3:
Windows(PPN).Activate
Sheets("PPAPs").Select
For Each lo In ActiveSheet.ListObjects
lo.AutoFilter.ShowAllData
Next lo
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Cells.EntireColumn.Hidden = False
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=5, Criteria1:="="
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=4, Criteria1:=10, _
Operator:=11, Criteria2:=0, SubField:=0
If ActiveSheet.ListObjects("PPAP").Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
GoTo NextPP4
End If
Range("A1").Select
ActiveSheet.ListObjects("PPAP").DataBodyRange.Columns("A:G").Select
Selection.SpecialCells(xlCellTypeVisible).Copy
Windows("Eng_QA Dashboard.xlsm").Activate
Sheets("PPAPs").Select
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
NextPP4:
Windows(PPN).Activate
Sheets("PPAPs").Select
For Each lo In ActiveSheet.ListObjects
lo.AutoFilter.ShowAllData
Next lo
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
ActiveSheet.ShowAllData
End If
Cells.EntireColumn.Hidden = False
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=5, Criteria1:="="
ActiveSheet.ListObjects("PPAP").Range.AutoFilter Field:=4, Criteria1:=12, _
Operator:=11, Criteria2:=0, SubField:=0
If ActiveSheet.ListObjects("PPAP").Range.Columns(1).SpecialCells(xlCellTypeVisible).Count = 1 Then
GoTo NextPP5
End If
Range("A1").Select
ActiveSheet.ListObjects("PPAP").DataBodyRange.Columns("A:G").Select
Selection.SpecialCells(xlCellTypeVisible).Copy
Windows("Eng_QA Dashboard.xlsm").Activate
Sheets("PPAPs").Select
For Each cell In ws.Columns(1).Cells
If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("A1").Select
Application.CutCopyMode = False
NextPP5:
Workbooks(PPN).Close False
Windows("Eng_QA Dashboard.xlsm").Activate
End Sub