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

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
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,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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