blog how to, blog trick, blog tips, tutorial blog, blog hack

How to Add characters in each cell of MS Excel

If you have MSExcel sheet with 100 cells filled with 001-100. And suppose you need to add "A" in front all of them. You dont have to work a whole long time to do it. All you have to do is make one Macro in VB.

Option Explicit

Sub Add_A()
Dim Last, Z As Variant, X As Variant
Sheets("Sheet1").Select
{here add title of your sheet}
Last = ActiveCell.SpecialCells(xlLastCell).Address
ActiveSheet.Range(Cells(1, 1), Last).Select
Z = Selection.Address
{taking adress}
For Each X In ActiveSheet.Range(Z)
{working while...}
If Len(X) > 0 Then
{finding cell with content}
X.FormulaR1C1 = Chr(65) & X.Text
{65 is code for 'A'}
Else
X.FormulaR1C1 = ""
{change nothing if cell is empty }
End If
Next
End Sub


Save this like new Macro and run it. Macro "Add_A" will add "A" in front of cells content. You can change "A" with other characters to yield corresponding results.

0 comments:

Post a Comment

 

© Copyright by Hanly Y Nadackal(systemsharks.blogspot.com)2009-2010