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

sspatriots

Well-known Member
Joined
Nov 22, 2011
Messages
572
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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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,215,071
Messages
6,122,964
Members
449,094
Latest member
Anshu121

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