troubleshooting Question

Help with Excel Visual Basic code

Avatar of snailcat
snailcatFlag for United States of America asked on
Microsoft ExcelMicrosoft OfficeVB Script
12 Comments2 Solutions425 ViewsLast Modified:
Hi,

Can anybody figure out the problem with this code? I am trying to use table formatting on a worksheet.
The code should figure out the range of data and then format to TableStyleLight8.  When I debug with my file the range seems to be finding the last column (O) but the table format is being applied and missing the last column.

Thanks
Dim LastRow As Long
    Dim LastCol As Long
    
    LastRow = Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = Cells(LastRow, Columns.Count).End(xlToLeft).Column
    Range("A1" & ":" & Cells(LastRow, LastCol).Address).Select
    


    ActiveSheet.ListObjects.Add(xlSrcRange, Range("A1" & ":" & Cells(LastRow, LastCol).Address), , xlYes).Name = _
        "Table1"
    Range("Table1[#All]").Select
    ActiveSheet.ListObjects("Table1").TableStyle = "TableStyleLight8"

Open in new window

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 2 Answers and 12 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 12 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros