+ Reply to Thread
Results 1 to 6 of 6

Can't increment Alphanumeric string by one

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,491

    Can't increment Alphanumeric string by one

    Attached file 160206 Text Autonumber.xlsm opens with Dashboard containing button that opens Order Form spreadsheet.

    When the Order Form is called, I want the Macro to find the latest Job Number in the Job Database worksheet (e.g. "Job 5"), increment it by one as the next number in sequence ("Job 6"), enter that in the next row down, and copy it to Cell C3 in the Order Form.

    The "click and drag" approach throws a "1004" error on the Selection Autofill line ("Autofill method of Range class failed")

    Option Explicit
    
    Sub NextOrder()
    
    Dim b As Long, c As Long
    
    Sheet1.Activate
    b = Range("B65536").End(xlUp).Row
    c = Range("B65536").End(xlUp).Row + 1
    
    Selection.AutoFill Destination:=Range("B" & b, Range("B" & c)), Type:=xlFillDefault
    
    Sheet2.Select
    Range("C3") = Sheet1.Range("B" & c)
    
    End Sub
    Any pointers or suggestions received gratefully as ever.

    Ochimus

  2. #2
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,028

    Re: Can't increment Alphanumeric string by one

    Try this:
    Sub NextOrder()
    
    Dim b As Long, c As Long
    Dim job As String
    
      Sheet1.Activate
    
      c = ActiveSheet.Range("B:B").Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
      job = "Job " & c - 1
    
      Range("B" & c) = job
      Sheet2.Activate
      Range("C3") = job
    
    End Sub

  3. #3
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Can't increment Alphanumeric string by one

    Rather than using the .Select or . Activate function that would slow the code down, and have your screen jump from sheet to sheet, try this;

    Sub NextOrder()
    
    Dim lr As Long
    Dim c As String
    
    With Sheets("JOB DATABASE")
        lr = .Cells(Rows.Count, "B").End(xlUp).Row
        c = "Job " & lr
        .Cells(lr + 1, 2) = c
    End With
    
    With Sheets("ORDER FORM")
        .Range("C3") = c
    End With
    
    End Sub
    I'm guessing there will be more to this code, so also include;
    Application.ScreenUpdating
    as part of your final code.

    It would be inserted in this manner;

    Sub NextOrder()
    
    Dim lr As Long
    Dim c As String
    
    Application.ScreenUpdating = False
    
    With Sheets("JOB DATABASE")
        lr = .Cells(Rows.Count, "B").End(xlUp).Row
        c = "Job " & lr
        .Cells(lr + 1, 2) = c
    End With
    
    With Sheets("ORDER FORM")
        .Range("C3") = c
    End With
    
    Application.ScreenUpdating = True
    
    End Sub
    Last edited by Jim885; 02-06-2016 at 10:12 AM.
    If I helped in any way, please click the star

  4. #4
    Valued Forum Contributor
    Join Date
    02-02-2016
    Location
    Indonesia
    MS-Off Ver
    Office 365
    Posts
    1,028

    Re: Can't increment Alphanumeric string by one

    Quote Originally Posted by Jim885 View Post
    Rather than using the .Select or . Activate function that would slow the code down, and have your screen jump from sheet to sheet, try this;
    Hi, Jim.
    Thanks for the advice. I'll keep that in mind.

  5. #5
    Forum Contributor
    Join Date
    02-24-2013
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    317

    Re: Can't increment Alphanumeric string by one

    Quote Originally Posted by Akuini View Post
    Hi, Jim.
    Thanks for the advice. I'll keep that in mind.
    Akuini,
    Glad it all worked out. You're welcome.


    Ochimus,
    Thanks for the rep.

  6. #6
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365 Version 2501 64-bit
    Posts
    1,491

    Re: Can't increment Alphanumeric string by one

    Thanks to both for prompt response and solutions.

    Ochimus

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 11-30-2016, 02:38 AM
  2. [SOLVED] Alphanumeric Increment based on previous row value
    By JusticeEmpire in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 06-06-2015, 01:14 PM
  3. Increment Alphanumeric Value of a Cell on each print job
    By rudygortiz in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-12-2014, 03:55 PM
  4. [SOLVED] Need code to pull numeric data out of an alphanumeric string (string not constant)
    By harrydnyc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-09-2013, 04:44 PM
  5. Replies: 12
    Last Post: 03-20-2013, 05:46 PM
  6. [SOLVED] Remove numbers from alphanumeric string. No standard format to the string.
    By ricunger in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 10-20-2012, 01:43 PM
  7. Replicate and increment alphanumeric keywords?
    By toolsavvy in forum Excel General
    Replies: 7
    Last Post: 12-16-2007, 03:02 AM

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