Table not expanding

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
I have written the following code that clears a page of data, copies the new data from another book, selects the new region and turns it into a table. It all works except when I add new data it shows up but the added rows do not format alternating row colors like the rest of the table. They are the background color instead.

Code:
Sub getData()
Dim table As ListObject
Workbooks("Front Desk.xlsm").Sheets("Search Page").Unprotect Password:="*********"
Workbooks("Front Desk.xlsm").Sheets("Search Page").Range("B14").CurrentRegion.ClearContents
Workbooks("Intake Data.xlsx").Sheets("Intake Data").Range("A1").CurrentRegion.Copy
Workbooks("Front Desk.xlsm").Sheets("Search Page").Range("B14").PasteSpecial xlPasteValues
Set table = Sheet1.ListObjects.Add(xlSrcRange, Workbooks("Front Desk.xlsm").Sheets("Search Page").Range("B14").CurrentRegion, , xlYes)
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,493
Office Version
365, 2010
Platform
Windows
When you add "new data", are you referring to additional data other than what is initially being dealt with in the above code. If so, what is the code you are using to add the additional data.
 

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
When you add "new data", are you referring to additional data other than what is initially being dealt with in the above code. If so, what is the code you are using to add the additional data.
I clear all of the old data (current data) and paste new data in the same place.
 

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
When you add "new data", are you referring to additional data other than what is initially being dealt with in the above code. If so, what is the code you are using to add the additional data.
Only code listed above.
 

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
Looks like this issue is related to the fill color of the cells. How do I set the fill color to a range to no fill?
 

igold

Well-known Member
Joined
Jul 8, 2014
Messages
2,493
Office Version
365, 2010
Platform
Windows
If the name of your Table is Table1 you could use this:

Code:
With Range("Table1[#All]").Interior
        .Pattern = xlNone
        .TintAndShade = 0
        .PatternTintAndShade = 0
End With
 

Kevin0427

Board Regular
Joined
Mar 31, 2016
Messages
69
Fixed it with this code if anyone is interested. I have seen lots of threads on how to do it with no success. This makes a table that alternates the color but you have to set the interior color to 0 for it to show through on the cells you want and it works when filtered too.

Code:
SearchPage.Range("B14").CurrentRegion.ClearContents
Workbooks(dataBook).Sheets("Intake Data").Range("A1").CurrentRegion.Copy
SearchPage.Range("B14").PasteSpecial xlPasteValues
totalrows = SearchPage.Cells(Rows.Count, 7).End(xlUp).Row
SearchPage.Range("B15:T" & totalrows).Interior.ColorIndex = 0
SearchPage.ListObjects.Add(xlSrcRange, SearchPage.Range("B14").CurrentRegion, , xlYes).Name = "SearchData"
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,102,285
Messages
5,485,846
Members
407,521
Latest member
marita

This Week's Hot Topics

Top