Excel Table - VBA Macro to automatically update formatting if a line is deleted.

BekahBu

New Member
Joined
Jun 12, 2013
Messages
1
The below macro takes data from the "OUTPUT_SPEC_PHARMACIES" tab and inserts it into a table on the "Pharmacy_Breakdown" tab. The table itself updates automatically if any new data is entered or deleted in the "OUTPUT_SPEC_PHARMACIES" tab. However, if data is deleted, the formatting of the table remains with nothing in it.

How can I change the macro to have the formatting update as well?

Thank you!!



Sub x()
Dim WS As Worksheet, WS2 As Worksheet
Set WS = ThisWorkbook.Worksheets("Pharmacy_Breakdown")
Set WS2 = ThisWorkbook.Worksheets("OUTPUT_SPEC_PHARMACIES")
Dim i As Long, j As Long
Dim num_rows As Long


num_rows = WorksheetFunction.CountA(WS2.Range("A:A"))
WS.Range("A6:H10000").ClearContents
For i = 5 To num_rows
For j = 1 To 8
WS.Cells(i, j) = WS2.Cells(i, j)
Next j
Next i




End Sub
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,215,459
Messages
6,124,944
Members
449,198
Latest member
MhammadishaqKhan

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