Thursday, 7 April 2011

How to add a tab character in VBA

Adding information to a spreadsheet, word document etc is one thing but most of the time you will need to add some formatting. VBA_logo

A tab character may be necessary to improve the appearance of your entry so this will need to be accommodated in your VBA code.

You can add a Tab character in your VBA code by using one of the following :
  1. Chr(9)
  2. vbTab
Here is an example of the code in use :

phoneDets = “Phone number : “ & Chr(9) & Chr(9) & “07896541243”

This code is assigning the string ‘Phone number :’ with two tabs inbetween and then the actual phone number.

So the output will be :

Phone number                                  07896541243.


No comments:

Post a Comment