View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Neil G Neil G is offline
external usenet poster
 
Posts: 3
Default Generate numbers for labels

Edwin,

That's just what I wanted.... well almost!
I'd like the first cell that's written to be the word 'List' (The Avery
Wizard takes the first line as the <<Merge field.

Regards
Neil

"Edwin Tam (MS MVP)" wrote in message
...
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 Integer
With ActiveSheet.Columns(1)
For tmp = 1 To 48 * 2 'change the number of sheet here
'may set the prefix in this line
.Cells(tmp).Value = "K81011" & "_ " & Format(tmp, "000")
Next
End With
End Sub
'----------------------------------------------------



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 Integer
Dim response
Dim response2
Do
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 * response
.Cells(tmp).Value = UCase(response2) & "_ " & Format(tmp, "000")
Next
End With
End Sub
'----------------------------------------------------


Regards,
Edwin Tam