UrbanPro
true

Learn Advanced VBScript from the Best Tutors

  • Affordable fees
  • 1-1 or Group class
  • Flexible Timings
  • Verified Tutors

Search in

Macros/VBA Function - Format

Karthik Dale
29/03/2017 0 0

Hi VBA/Macro Learners,

Today we will see how to  use FORMAT Function in VBA to get modify the format of Numbers,Dates,Times & String.

Syntax: FORMAT(expression,format,[firstdayofweek],[firstweekofyear])

 

'Ex1: Modify the Format of Numbers using FORMAT function

SUB Format_Numbers()

MsgBox format(8686836999, "####-###-###")

'Output: '8686-836-999'

MsgBox format(143.5, "#,##.00")

'Output: '143.50'

MsgBox format(1729.4, "Currency")

'Output: '$1,729.40'

MsgBox format(0.9156, "Percent")

'Output: '91.56%'

MsgBox format(1729.4, "Standard")

'Output: '1,729.40'

End Sub

'Ex2: Modify the Format of Text using FORMAT function

Sub FORMAT_Text()

MsgBox format("EXCEL IS MAGIC", "<")

'Output: 'excel is magic' (convert text to lower case)

MsgBox format("excel is magic", ">")

'Output: 'EXCEL IS MAGIC' (convert text to upper case)

End Sub

'Ex3: Modify the Format of Dates using FORMAT function

Sub FORMAT_Dates()

MsgBox format("3/21/2017", "Short Date")

'Output: '3/21/2017'

MsgBox format("3/21/2017", "Medium Date")

'Output: '21-Mar-17'

MsgBox format("3/21/2017", "Long Date")

'Output: 'Tuesday, March 21, 2017'

MsgBox format("3/21/2017", "mmm dd")

'Output: 'Mar 21'

End Sub

'Ex4: Modify the Format of Time using FORMAT function

Sub FORMAT_Time()

MsgBox format("6:30:45", "Short Time")

'Output: '06:30'

MsgBox format("6:30:45", "LONG Time")

'Output: '6:30:45 AM'

MsgBox format("6:30:45", "MEDIUM Time")

'Output: '06:30 AM'

MsgBox format("14:30:45", "HH:MM")

'Output: '14:30'

End Sub

0 Dislike
Follow 0

Please Enter a comment

Submit

Other Lessons for You

Microsoft Outlook
Microsoft Outlook is the preferred email client used to access Microsoft Exchange Server email. Not only does Microsoft Outlook provide access to Exchange Server email, but it also includes contact, calendaring...

HTML (Hypertext Markup Language)
HTML (Hypertext Markup Language) is the set of markup symbols or codes inserted in a file intended for display on a World Wide Web browser page. The markup tells the Web browser how to display a Web page's...

Hidden Gems of MS Excel - Reapply Filter
Q) How does Reapply help? Or, when could I use Reapply?A) e.g. Please refer following screenshot: You are Analysing a Dataset.You have applied Filter on Date Column, to focus on April month entries.You...

Top 30 formulas in Excel
Generally, we are only use maximum "30 formulas" in our day to day routine. let's explore with below formulas and let me know which one is your favorite. Vlookup If Iferror Sum Count Sumif Countif CountA Index Match Left Right Mid Tri...

10 Best Job Interview Tips for Jobseekers
10 Best Job Interview Tips for Jobseekers:- 1. Conduct Research on the Employer, Hiring Manager, and Job Opportunity2. Review Common Interview Questions and Prepare Your Responses3. Dress for Success4....

Looking for Advanced VBScript Training?

Learn from Best Tutors on UrbanPro.

Are you a Tutor or Training Institute?

Join UrbanPro Today to find students near you
X

Looking for Advanced VBScript Classes?

The best tutors for Advanced VBScript Classes are on UrbanPro

  • Select the best Tutor
  • Book & Attend a Free Demo
  • Pay and start Learning

Learn Advanced VBScript with the Best Tutors

The best Tutors for Advanced VBScript Classes are on UrbanPro

This website uses cookies

We use cookies to improve user experience. Choose what cookies you allow us to use. You can read more about our Cookie Policy in our Privacy Policy

Accept All
Decline All

UrbanPro.com is India's largest network of most trusted tutors and institutes. Over 55 lakh students rely on UrbanPro.com, to fulfill their learning requirements across 1,000+ categories. Using UrbanPro.com, parents, and students can compare multiple Tutors and Institutes and choose the one that best suits their requirements. More than 7.5 lakh verified Tutors and Institutes are helping millions of students every day and growing their tutoring business on UrbanPro.com. Whether you are looking for a tutor to learn mathematics, a German language trainer to brush up your German language skills or an institute to upgrade your IT skills, we have got the best selection of Tutors and Training Institutes for you. Read more