I have a question here. Currently, I am working with a labeling project. Is there any way for me to select different style of labeling from the modules? I mean for now my code can only do 4 by 4 labeling, which is 1A, 1B, 1C, 1D, 2A, 2B, 2C, 2D and so on only. I want my code to do labeling from 1 by 1 labeling until 20 by 20 labeling. Can you please help me? Thank you in advance. The user can just typed "2 By 2", "3 By 3" and so on in the textbox from a userform to generate the output. In my code, I tried using case statement but it didn't works. These are the code that I edited and now it can't run:
Option Explicit
Public A, B As Integer
Sub AutoLabel()
' to label the cell in term of 1A, 1B and etc
A = 1
B = 1
End Sub
Private Sub cmdOK_Click() ' name of my textbox OK
Sub Select_Case_Label()
Dim Cell As Range
Cell = TextBox1.value
With Selection
' allign text so that it is centered between the top and bottom of the cell
.HorizontalAlignment = xlCenter
' allign text so that it is centered between the left and right of the cell
.VerticalAlignment = xlCenter
SR = .Row
SC = .Column
LR = SR + .Rows.Count - 1
LC = SC + .Columns.Count - 1
End With
With Selection
Select Case Cell.value
' the selection of style is 1 By 1 until 20 By 20
Case "1 By 1"
' to input the first cell as 1A, and next cell as 1B and etc
For Each Cell In Selection
Cell.value = B & Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", A, 1)
A = A + 1
If A = 2 Then A = 1: B = B + 1
Next Cell ' run next selected cell by user
Case "2 By 2"
' to input the first cell as 1A, and next cell as 1B and etc
For Each Cell In Selection
Cell.value = B & Mid("ABCDEFGHIJKLMNOPQRSTUVWXYZ", A, 1)
A = A + 1
If A = 3 Then A = 1: B = B + 1
Case Else
MsgBox "Your number is out of the range."
End Select
End With
End Sub
Bookmarks