Results 1 to 3 of 3

Select Different Style of Numbering From TextBox Using Macro Excel

Threaded View

  1. #1
    Registered User
    Join Date
    03-15-2017
    Location
    Malaysia
    MS-Off Ver
    Microsoft 2010
    Posts
    24

    Select Different Style of Numbering From TextBox Using Macro Excel

    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
    Last edited by Ruffy; 04-05-2017 at 02:02 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Select a Textbox from a module upon opening excel
    By exclusiveicon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-19-2014, 10:46 AM
  2. Excel Macro Sends Command When Prompted by AS400 Style System
    By DHPorter04 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-01-2013, 04:03 PM
  3. [SOLVED] Changing a textbox style depending on the value of a cell
    By evertjvr in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-10-2012, 04:24 AM
  4. [SOLVED] How to Select a Whole Column Using Cells(1,1) Style?
    By One-Eyed Enos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2012, 05:18 PM
  5. Replies: 1
    Last Post: 04-20-2012, 09:49 PM
  6. Select a Style in Excel 2007
    By ExcelTip in forum Tips and Tutorials
    Replies: 0
    Last Post: 11-07-2007, 10:18 AM
  7. Select Cells by Style
    By Werner Rohrmoser in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-16-2006, 03:15 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1