Convert Table to Range in all sheets but only for a given range

WojtekP

New Member
Joined
Aug 14, 2019
Messages
4
VBA Code:
Sub TurnTablesIntoRanges()
Dim wks As Worksheet, objList As ListObject
For Each wks In ActiveWorkbook.Worksheets
For Each objList In wks.ListObjects
objList.Unlist
Next objList
Next wks
End Sub

Hello,

A novice here... I have few tables in each workbook in a multiply sheets excel file.
Can you help me to change this VBA above to be able to only convert tables that are in rows let's say: 20-100 and leave other tables in each workbook intact?

Thanks in advice for your ideas.

Best regards,
Wojtek
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Try...

VBA Code:
Sub TurnTablesIntoRanges()
    Dim wks As Worksheet, objList As ListObject
    For Each wks In ActiveWorkbook.Worksheets
        For Each objList In wks.ListObjects
            If Union(objList.Range, wks.Rows("2:10")).Address = "$2:$10" Then
                objList.Unlist
            End If
        Next objList
    Next wks
End Sub

Note to convert tables that only lie partially within Rows 2 to 10, replace...

Code:
            If Union(objList.Range, wks.Rows("2:10")).Address = "$2:$10" Then

with

Code:
            If Not Intersect(objList.Range, wks.Rows("2:10")) Is Nothing Then

Hope this helps!
 
Upvote 0
another option for you

Whole of table must be between rows 20 and 100 to be converted
VBA Code:
Sub TurnTablesIntoRanges()
    Dim wks As Worksheet, objList As ListObject, F As Long, L As Long
    
    For Each wks In ActiveWorkbook.Worksheets
        For Each objList In wks.ListObjects
            With objList.Range
                F = .Cells(1, 1).Row
                L = F + .Rows.Count - 1
                If F > 19 And L < 101 Then objList.Unlist
            End With
        Next objList
    Next wks
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,077
Messages
6,128,680
Members
449,463
Latest member
Jojomen56

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