Create table finding last table row with data not in first column

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
585
Office Version
  1. 365
Platform
  1. Windows
Good afternoon,

I have a situation where I've tried both methods below to create a table on a worksheet that starts in row 2 for the headers. The problem is that in the middle of the list of data, there are three rows with no data in the first 10 table cells (or so). When I try the first method below, I get my headers on row 2, but it only captures data for the table to the rows of the table that have blanks in the first 10 table cells (or so). When I use the ".CurrentRegion" method, I can't make it start at row 2 for the headers, however, it does capture every row in the set of data when creating the table.
Any recommendations would be greatly appreciated.

Thanks, SS


Attempt using "Range(.End(xlDown)" method:
VBA Code:
    If TableExists(Worksheets("COMM - In Production"), "COMM_In_Production") Then
    
'        MsgBox "Table1 Exists on sheet " & ActiveSheet.Name

    Else
    
'        MsgBox "Table1 Does Not Exist on sheet " & ActiveSheet.Name

        With Worksheets("COMM - In Production").Range("A2")
        .Parent.ListObjects.Add(xlSrcRange, Range(.End(xlDown), .End(xlToRight)), , xlYes).Name = "COMM_In_Production"
        
        
        End With
         
    End If



Attempt using ".CurrentRegion" method:
VBA Code:
    If TableExists(Worksheets("COMM - In Production"), "COMM_In_Production") Then
    
'        MsgBox "Table1 Exists on sheet " & ActiveSheet.Name

    Else
    
'        MsgBox "Table1 Does Not Exist on sheet " & ActiveSheet.Name

        With Worksheets("COMM - In Production").Range("A2")
        .Parent.ListObjects.Add(xlSrcRange, Range("A2").CurrentRegion, , xlYes).Name = "COMM_In_Production"
        
        
        End With
         
    End If
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Try offsetting the current region and resizing it to eliminate the blank row from being part of the table
VBA Code:
Range("A2").CurrentRegion.Offset(1).Resize(.CurrentRegion.Rows.Count - 1)
 
Upvote 0
Solution
Try offsetting the current region and resizing it to eliminate the blank row from being part of the table
VBA Code:
Range("A2").CurrentRegion.Offset(1).Resize(.CurrentRegion.Rows.Count - 1)
That did it. Thank you
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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