How to add a condition to a macro If the name does not exist, continue to Next.

Slavio

Board Regular
Joined
Mar 28, 2021
Messages
59
Office Version
  1. 365
Platform
  1. Windows
  2. Web
I have a Macro that converts the table back to Range.
The problem occurs if there is no table name in Sheet3.
I need the macro to skip this step then and continue

VBA Code:
Sub ConvertTableToRange5()

    Dim rList As Range
    Dim ws As Worksheet
    
    ' Source - delete table Name
        Sheets("Sheet3").Select
    For Each ws In Worksheets(Array("SourceTab"))
    
   'If "SourceTab" dont Exist Then Next = >>> HERE I need a code
    
    With ws.ListObjects(1)
    
        Set rList = .Range
        .Unlist                           ' convert the table back to a range
    End With
    
    With rList
        .Interior.ColorIndex = xlColorIndexNone
        .Font.ColorIndex = xlColorIndexAutomatic
        .Borders.LineStyle = xlLineStyleNone
    End With
    Next ws
    
    Cells.Select
    Selection.Delete Shift:=xlUp
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Try this.
VBA Code:
        If ws.ListObjects.Count > 0 Then
            With ws.ListObjects(1)
                Set rList = .Range
                .Unlist                           ' convert the table back to a range
            End With

            With rList
                .Interior.ColorIndex = xlColorIndexNone
                .Font.ColorIndex = xlColorIndexAutomatic
                .Borders.LineStyle = xlLineStyleNone
            End With
        End If
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: How to add a condition to a macro If the name does not exist, continue to Next. - OzGrid Free Excel/VBA Help Forum
If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Cross-posting (posting the same question in multiple forums) is not against our rules, but how they are done is covered in Article 13 of the Forum Rules .

Also, don't forget to follow and read the link at the end of the rule!

Crosshair posted at: How to add a condition to a macro If the name doesn't exist, continue with the next one. - OzGrid Free Excel / VBA Help Forum
If you have placed the question in more than one place, also provide links to them.

If you contribute cross-post in the future and also provide links, this should not be a problem.
OK. Thank you for warning. I will respect that.
 
Upvote 0
Try this.
VBA Code:
        If ws.ListObjects.Count > 0 Then
            With ws.ListObjects(1)
                Set rList = .Range
                .Unlist                           ' convert the table back to a range
            End With

            With rList
                .Interior.ColorIndex = xlColorIndexNone
                .Font.ColorIndex = xlColorIndexAutomatic
                .Borders.LineStyle = xlLineStyleNone
            End With
        End If
I've already solved it on the forum
Thank You
 
Upvote 0
Wasn't it royUK that solved it.:)
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,918
Members
449,195
Latest member
Stevenciu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top