» Format table depending on number formats using VBA in Microsoft Excel
CATEGORY - Formating in VBA
VERSION - All Microsoft Excel Versions
Question: The columns sheet data are to be formatted according to the number format template in sheet "Formats"
Answer:
Insert the following code in standard module.
Sub Formatting()
Dim wks As Worksheet
Dim intCol As Integer
Dim strCol As String
Dim txt As String
Set wks = Worksheets("Formats")
intCol = 1
Do Until IsEmpty(wks.Cells(1, intCol))
txt = wks.Cells(2, intCol)
Do Until InStr(txt, ",") = 0
strCol = Left(txt, InStr(txt, ",") - 1)
Columns(CInt(strCol)).NumberFormat = wks.Cells(1, intCol).Value
txt = Right(txt, Len(txt) - InStr(txt, ","))
Loop
Columns(CInt(txt)).NumberFormat = wks.Cells(1, intCol).Value
intCol = intCol + 1
Loop
End Sub
Book Store:
Recommended Books:
- Special Edition Using Microsoft Word 2002
- The 22 Immutable Laws of Branding
- Successful Business Planning in 30 Days: A Step-By-Step Guide for Writing a Business Plan and Starting Your Own Business
- Final Accounting: Ambition, Greed and the Fall of Arthur Andersen
- The 22 Immutable Laws of Marketing : Exposed and Explained by the World's Two
- Your First Business Plan: A Simple Question and Answer Format Designed to Help You Write Your Own Plan (3rd Ed)
No comments have been submitted.

