View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Edwin Tam (MS MVP) Edwin Tam (MS MVP) is offline
external usenet poster
 
Posts: 48
Default Generate numbers for labels

Below is the simple macro which does the task
It uses a FOR-NEXT loop to generate the sequential codes. You can also set the "number of sheets" there

'---------------------------------------------------
Sub example(
Dim tmp As Intege
With ActiveSheet.Columns(1
For tmp = 1 To 48 * 2 'change the number of sheet her
'may set the prefix in this lin
.Cells(tmp).Value = "K81011" & "_ " & Format(tmp, "000"
Nex
End Wit
End Su
'---------------------------------------------------


The above macro can be extended to use InputBoxes to collect user input variables
(It also contains a line to ensure the prefix is Capital.

'---------------------------------------------------
Sub example2(
Dim tmp As Intege
Dim respons
Dim response
D
response = InputBox("Please enter the number of sheets."
Loop Until IsNumeric(response
response2 = InputBox("Please enter the prefix."
With ActiveSheet.Columns(1
For tmp = 1 To 48 * respons
.Cells(tmp).Value = UCase(response2) & "_ " & Format(tmp, "000"
Nex
End Wit
End Su
'---------------------------------------------------

Regards
Edwin Ta