Follow these steps
- We need to enable Developer Toolbar with the following steps
- Click the Office Button
- Click Excel Options
- Click Popular, select "Show Developer tab in the Ribbon" Checkbox
- Edit Macro settings in Excel by doing the following steps
- On the Developer tab, in the Code group, click Macro Security
Note: If the Developer tab is not displayed, do step 1
- In the Macro Settings category, under Macro Settings, click the option Disable all macros with Notification
- Save the excel workbook
- Select Developer Ribbon Tab and Click on Visual Basic
- Microsoft Visual Basic Editor will be opened
- Click on Insert menu and then click on Module
- Copy and paste the following code
- Enter your data as a table format
- Select Developer Ribbon Tab and Click on Macros
- Now you can see one macro with the name Table_xls_Format
- Click on Run
- See the data now. It will be in table format with proper header and data alignment
- You can change the macro code by clicking edit button in macro window.
Sub Table_Xls_Format()
'Selecting Header Row
Dim header_row As Range
Set header_row = Range("a1", Range("a1").End(xlToRight))
header_row.Select
'Heading Bold, Aqua Color
header_row.Font.Bold = True
header_row.HorizontalAlignment = xlCenter
header_row.Font.ColorIndex = 42
header_row.Font.Italic = False
header_row.Font.Underline = False
'Selecting data
Dim total_data As Range
Set total_data = Range("A1").CurrentRegion
total_data.Select
total_data.Font.Bold = False
total_data.Font.Italic = False
total_data.Font.Underline = False
'Font:Couriernew , 10
total_data.Font.Name = "Courier New"
total_data.Font.Size = 10
'Full Border
total_data.Borders.LineStyle = 1
'Autofit Column Width
Selection.Columns.AutoFit
'Autosave the workbook
ActiveWorkbook.Saved = True
End Sub
No comments:
Post a Comment