Consulting

Results 1 to 3 of 3

Thread: Start From Last Column - Sequential Number

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    Start From Last Column - Sequential Number

    good day,

    now i know how to sequentially number, that works well




      ws.Range("G7:AC7").Cells = "###"                    
    
        For Each oCell In ws.Range("G7:AC7").Cells
        oCell.Replace What:="###", Replacement:=i
        i = i + 1
      
        Next oCell
    I wanted to know what was the mechanism for me to number in reverse

    instead of 0,1,2,
    G7, H7,I7

    could i make

    0,1,2,
    Ac7, AB7, AA7 etc


    start numbering from my last column to the first

    well i couldnt find anything, im sure it may be something simple?
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    You mean something like this?

    G7 = 23
    AC7 =1


    Option Explicit
    
    Sub test()
        Dim i As Long
        Dim oCell As Range
        
        ActiveSheet.Range("G7:AC7").Cells = "###"
        i = ActiveSheet.Range("G7:AC7").Cells.Count
    
        For Each oCell In ActiveSheet.Range("G7:AC7").Cells
            oCell.Replace What:="###", Replacement:=i
            i = i - 1
        Next oCell
        
    End Sub

    or

    G7 = 22
    AC7 =0



    Option Explicit
    Sub test()
        Dim i As Long
        Dim oCell As Range
        
        ActiveSheet.Range("G7:AC7").Cells = "###"
        i = ActiveSheet.Range("G7:AC7").Cells.Count - 1
    
        For Each oCell In ActiveSheet.Range("G7:AC7").Cells
            oCell.Replace What:="###", Replacement:=i
            i = i - 1
        Next oCell
        
    End Sub
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Hello Paul,

    nice to see you.

    i only managed to get the i = i - 1 correct

    but i couldnt work out the cells in reverse

    its all simple untill i get my hands on it

    thanks for the code and great eve
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


Posting Permissions

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