View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_589_] Leith Ross[_589_] is offline
external usenet poster
 
Posts: 1
Default Simple code to append numbers to the existing data in the cells


Hello Hemang Shah,

This macro will prompt you for a starting number and then appen it t
the data in the cells you have selected. The cells need not b
contiguous.

Add a VBA module to your project and paste this macro into. You ca
then assign the macro to an object or run it using the Macro Dialo
(press ALT+F8 while in Excel).


Code
-------------------

Sub AppendNumber()

Dim Answer
Dim ChoosenCells As Range
Dim I As Long

Answer = InputBox("Enter your starting sequence number.")
If Answer = "" Then Exit Sub
I = Answer

For Each ChoosenCell In Selection
With ChoosenCell
.Value = I & .Text
End With
I = I + 1
Next ChoosenCell

End Sub

-------------------


Sincerely,
Leith Ros

--
Leith Ros
-----------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...fo&userid=1846
View this thread: http://www.excelforum.com/showthread.php?threadid=55481