Consulting

Results 1 to 4 of 4

Thread: Solved: Help with Formula please

  1. #1

    Solved: Help with Formula please

    Hi

    I have the following formula which copies a 7 characters from sheet1 to sheet 2 - the characters could be 3 letters & 4 numbers OR 4 letters and 3 numbers. It also adds 1 to the sequence

    =LEFT(Sheet1!H20,4)&RIGHT(Sheet1!H20,3)+1

    works fine when there are 4 letters and 3 numbers e.g. YYYY111 goes to YYYY112, but when YYY6005 it comes out as YYY66 - loses the 2 noughts.

    In this situation it works OK if change to

    =LEFT(Sheet1!H20,3)&RIGHT(Sheet1!H20,4)+1

    Is there a way to get these 2 formulas in to one to solve or maybe something in VBA?

    thanks
    Jon

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try

    =LEFT(Sheet1!H20,4)&TEXT(RIGHT(Sheet1!H20,3)+1,"000")
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    =CharsAndNums(Sheet1!H20)
    [VBA]Function CharsAndNums(Target As String) As String
    Dim A As Long
    Dim lCount As Long
    For A = 1 To Len(Target)
    Select Case Asc(Mid(Target, A, 1))
    Case 48 To 57 '0-9

    Case Else
    lCount = lCount + 1
    End Select
    Next
    A = Val(Right(Target, Len(Target) - lCount)) + 1
    CharsAndNums = Left(Target, lCount) & CStr(A)
    End Function[/VBA]
    David

  4. #4
    Thanks Guys,

    The formula works OK but can't seem to get the function to work

    regards
    Jon

Posting Permissions

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