Table formatting VBA CODE

shoun2502

New Member
Joined
Nov 14, 2018
Messages
45
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am looking for a vba code to have my customized table formatting as I need to execute the same for numerous table and is cumbersome without the code.


The details are mentioned below for the reference.


1. Text : Calibri 10
2. First Column, Row and Last Column Fill colour coding
RGB, Red:49, Green:133, Blue: 156


3 Rest all cells to be color filled
RGB , Red:219, Green:238, Blue:244


4 Text colour to be white & "Bold" for First Column and Row , Last Column


5 Text colour to be black for Remaining Cells




It would be indeed helpful if the forum could address the issue and help me writing the code and subsequently shall surely help me in saving a lot of time.
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try this:
This assumes you have no more then One table on same sheet.

Code:
Sub Format_Table()
Dim c As Long
'Modified  11/14/2018  6:16:46 AM  EST
With ActiveSheet.ListObjects(1).DataBodyRange
c = .Columns.Count
.Interior.Color = RGB(219, 238, 244)
.Font.Size = 10
.Name = "Calibri"
.Font.Color = vbBlack
.Columns(1).Interior.Color = RGB(49, 133, 156)
.Columns(1).Font.Color = vbWhite
.Columns(1).Font.Bold = True
.Columns(c).Interior.Color = RGB(49, 133, 156)
.Columns(c).Font.Color = vbWhite
.Columns(c).Font.Bold = True
.Rows(1).Interior.Color = RGB(49, 133, 156)
.Rows(1).Font.Color = vbWhite
.Rows(1).Font.Bold = True
End With
End Sub
 
Upvote 0
If you want to format all Tables on all sheets in your workbook the same.
Try this script
It will loop through all sheets in your workbook

Code:
Sub All_Tables_All_Sheets_New()
'Modified  11/14/2018  7:32:09 AM  EST
Dim T As ListObject
Dim c As Long
Dim i As Long
For i = 1 To Sheets.Count
    For Each T In Sheets(i).ListObjects
        With T.DataBodyRange
            c = .Columns.Count
            .Interior.Color = RGB(219, 238, 244)
            .Font.Size = 10
            .Name = "Calibri"
            .Font.Color = vbBlack
            .Columns(1).Interior.Color = RGB(49, 133, 156)
            .Columns(1).Font.Color = vbWhite
            .Columns(1).Font.Bold = True
            .Columns(c).Interior.Color = RGB(49, 133, 156)
            .Columns(c).Font.Color = vbWhite
            .Columns(c).Font.Bold = True
            .Rows(1).Interior.Color = RGB(49, 133, 156)
            .Rows(1).Font.Color = vbWhite
            .Rows(1).Font.Bold = True
        End With
    Next
Next
End Sub
 
Upvote 0
Please post all additional needs here in the forum.
Not in PM.

This is a forum Rule.

You asked:
Even I wanted to have inner borders to be white can u please help with the code.

Do you mean all Table borders
Not sure what inner borders means


 
Upvote 0
Thanks for the reply . I am also trying to replicate the last row with the coding

.Rows(c).Interior.Color = RGB(49, 133, 156)
.Rows(c).Font.Color = vbWhite
.Rows(c).Font.Bold = True

but Unfortunately the second last row is being executed. Could you please help with this error.

Thanks in anticipation
 
Upvote 0
If your using the script for all Tables on all sheets
Here is your added request for Borders

Code:
Sub All_Tables_All_Sheets_New()
'Modified  11/14/2018  7:55:14 AM  EST
Dim T As ListObject
Dim c As Long
Dim i As Long
For i = 1 To Sheets.Count
    For Each T In Sheets(i).ListObjects
        With T.DataBodyRange
            c = .Columns.Count
            .Interior.Color = RGB(219, 238, 244)
            .Font.Size = 10
            .Name = "Calibri"
            .Font.Color = vbBlack
            .Borders.LineStyle = xlContinuous
            .Borders.Color = vbWhite
            .Columns(1).Interior.Color = RGB(49, 133, 156)
            .Columns(1).Font.Color = vbWhite
            .Columns(1).Font.Bold = True
            .Columns(c).Interior.Color = RGB(49, 133, 156)
            .Columns(c).Font.Color = vbWhite
            .Columns(c).Font.Bold = True
            .Rows(1).Interior.Color = RGB(49, 133, 156)
            .Rows(1).Font.Color = vbWhite
            .Rows(1).Font.Bold = True
        End With
    Next
Next
End Sub
 
Upvote 0
Similarly, If I have Some data having borders not table Is it possible to execute the code in similar formatting.
With First,Last row and First Column.

Please do help me with that.
 
Upvote 0
Please take a minute to read the forum rules, especially on cross-posting, and then comply with them by adding the relevant links here. Thanks. :)
 
Upvote 0
Not sure what your now asking for.
You earlier said all is great.
If your saying you want special formatting for the last row.
Well the last row will always be changing as you add more to your table
So how would we do that?


Thanks for the reply . I am also trying to replicate the last row with the coding

.Rows(c).Interior.Color = RGB(49, 133, 156)
.Rows(c).Font.Color = vbWhite
.Rows(c).Font.Bold = True

but Unfortunately the second last row is being executed. Could you please help with this error.

Thanks in anticipation
 
Upvote 0

Forum statistics

Threads
1,224,299
Messages
6,177,754
Members
452,798
Latest member
mlance617

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