I have a sheet with multiple Excel named tables that copy the table data (within a certain named range) and pastes it into another sheet for recording purposes. However sometimes there may be no data, and I get a runtime error. So I am trying to work out how to create a loop or if statement to skip that table and move to the next one, but my VBA skills are limited to some recording and Googling and am lost as to how to incorporate this in my existing code...
Sub CopyTrackingHist()
' CopyTrackingHist Macro
Dim ws As Worksheet
Dim tblM As ListObject
Dim tblR As ListObject
Dim tblN As ListObject
Dim tblI As ListObject
Set ws = Sheets("Tracking")
Set tblM = ws.ListObjects("Maturities_Track")
Set tblR = ws.ListObjects("Rollovers_Track")
Set tblN = ws.ListObjects("NewDeal_Track")
Set tblI = ws.ListObjects("IntPay_Track")
Application.ScreenUpdating = False
'Daily Maturities Copied from Tracking Sheet to Historical sheet
Sheets("Tracking").Select
Range(tblM & "[[Date]:[Daily Flow Client Rate Interest Mar]]").Select
Selection.Copy
'Paste into Historical capture sheet
Sheets("Maturities_Hist").Select
Range("A1").Select
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Daily Rollovers copied to Historical Sheet
Sheets("Tracking").Select
Range(tblR & "[[Date Stlmt]:[Daily Flow Client Rate Interest Mar]]").Select
Selection.Copy
'Paste into Historical capture sheet
Sheets("Rollovers_Hist").Select
Range("A1").Select
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Daily New Deals table to Historical sheet
Sheets("Tracking").Select
Range(tblN & "[[Date Stlmt]:[Daily Flow Client Rate Interest Mar]]").Select
Selection.Copy
'Paste into Historical capture sheet
Sheets("NewDeals_Hist").Select
Range("A1").Select
Range("A1").End(xlDown).Offset(0, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'Daily Interest Payments copied to Historical Sheet
Sheets("Tracking").Select
Range(tblI & "[[Date]:[Daily Flow Client Rate Interest Mar]]").Select
Selection.Copy
'Paste into Historical capture sheet
Sheets("InterestPymts_Hist").Select
Range("A1").Select
Range("A1").End(xlDown).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
End Sub
The end user enters in information into each table, so I plan to use this macro before another macro that clears and resets the sheet. If you can also share how to plug this into the existing macro, that would be fabulous :) I am also open to feedback and suggestions to make the code more efficient ;) Thanks all