I didn't fount something useful for my problem although it seems to be a common problem. I have a simple old code of mine with a table of compnies data in one sheet. My code takes data based on a company name, finds a worksheet with that compny name inside the workbook and make few actions.
My problem starts when one of the sheets gets deleted and the the code stucks. I do in the code the same routine for every company, and I want it will fo to next company if it not finding worksheet with specific company name.
Can someone help with somthing that will work as an if
statement?
Here is the start of the code and two companies for example - YEDIDIM & BEHIRIM. the else is the same:
Sub Calculation_of_Change()
Application.ScreenUpdating = False
'refresh 2 PivoTableS
Dim pivot As PivotTable
Set pivot = Worksheets("PIVOT").PivotTables("PivotTable1")
pivot.RefreshTable
Set pivot = Sheets("PIVOT (-)").PivotTables("PivotTable1")
pivot.RefreshTable
'we need to delete the old data and replace it with new data
'YEDIDIM
'first we will delete all old data
Sheets("YEDIDIM").Select
Range("A2", Range("A2").End(xlDown)).Select
Selection.EntireRow.Delete
'for each sheet with data we will filter the PIVOT table and paste the new data so we could calculate the stats we want
Sheets("PIVOT").Activate
ActiveSheet.PivotTables("PivotTable1").PivotFields("ùí úú îôòì"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("ùí úú îôòì").PivotFilters. _
Add2 Type:=xlCaptionContains, Value1:="YEDIDIM"
Range("A5", Range("A5").End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("YEDIDIM").Select
Range("A2").PasteSpecial (xlPasteValues)
'BEHIRIM
'first we will delete all old data
Sheets("BEHIRIM").Select
Range("A2", Range("A2").End(xlDown)).Select
Selection.EntireRow.Delete
'for each sheet with data we will filter the PIVOT table and paste the new data so we could calculate the stats we want
Sheets("PIVOT").Activate
ActiveSheet.PivotTables("PivotTable1").PivotFields("ùí úú îôòì"). _
ClearAllFilters
ActiveSheet.PivotTables("PivotTable1").PivotFields("ùí úú îôòì").PivotFilters. _
Add2 Type:=xlCaptionContains, Value1:="BEHIRIM"
Range("A5", Range("A5").End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
Selection.Copy
Sheets("BEHIRIM").Select
Range("A2").PasteSpecial (xlPasteValues)