Consulting

Results 1 to 3 of 3

Thread: Start From Last Column - Sequential Number

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    402
    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 Wizard
    Joined
    Apr 2007
    Posts
    7,000
    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

    ------------------------------------------------------------------------------------------------------------------------
    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)
    (multiple files can be selected while holding Ctrl key) / 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
    402
    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
  •