Consulting

Results 1 to 5 of 5

Thread: Sequentially Number Placeholder in Cells

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

    Sequentially Number Placeholder in Cells

    folks,

    good day


    any one know how i can sequentially number this placeholder the %%

    the cell has


    %% Apple
    %% Banana
    %% Fruit

    After Numbering

    1 Apple
    2 Banana
    3 Fruit
    4
    etc

    I have researched and cant find this simple task,

    I am trying to think of a vba solution, becuase i had 1000 rows and i put formulas in it and i couldnt use my workbook the memory increased to 12MB i had to destroy my good work later

    How can i just number these placeholders in the colum

    thank you very much for any advice
    Cheers for your help

    dj

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


  2. #2
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    I managed to work out
    Sub SequentialCellNumber()
    
    Dim c As Range
    Dim cph As String
    Dim lngIndex As Long: lngIndex = 1
    
    cph = "%%"
    
    For Each c In Selection
    
    If c.Value <> "" Then c.Value = c.Value & cph & lngIndex
    
    lngIndex = lngIndex + 1
    
    Next
    End Sub
    So i need to do a search for the %% and then number them
    Cheers for your help

    dj

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


  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Happy to report i managed to work it out finally


    if any one needs to number a bunch of %% in theor cells i say this may suffice

    Sub Sequentially_Number_Cells()
    
    Dim lngIndex As Long: lngIndex = 1
    
    Dim oLastRow As Long, i As Long
    
    oLastRow = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 1 To oLastRow
    
    With Range("A" & i)
    .Value = Replace(.Value, "%%", lngIndex)     ' << Search and Replace here
    
    lngIndex = lngIndex + 1
    End With
    Next i
    
    End Sub
    so long as it does the job and i dont have to use that dreaded formula

    happy weekend all
    Cheers for your help

    dj

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


  4. #4
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    No looping
    Sub test()
    Dim Rng As Range
    Set Rng = Cells(1, 1).CurrentRegion
    Rng.Offset(, 1).FormulaR1C1 = "=SUBSTITUTE(RC[-1],""%%"",ROW())"
    Rng.Value = Rng.Offset(, 1).Value
    Rng.Offset(, 1).ClearContents
    End Sub
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Another way to do it thank you M,

    well i was very upset that Excel gave up on me.

    Never in my days had i known 1000 rows would cause such mischief.

    but then I was being very ambitious concatnating strings with all sorts.

    excel has millions of rows and it gave up on my 1000 rows

    oh well im glad i only did 2 columns of 1000 rows when it self combusted on me
    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
  •