Consulting

Results 1 to 3 of 3

Thread: Target Specific Array Elements Group

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

    Target Specific Array Elements Group

    folks,

    good day

    how may i target the elements of the replace array

    between 5 and 8

     Sub Target_Array()
        
    
        oSearch = Array(1, 2, 3)
        
        oReplace = Array(A, B, C, D, E, F, G, H, i, j, K, L, M)
    
        j=0
        For i = LBound(oSearch) To UBound(oSearch)
        
        For Each cel In ActiveSheet.Range("A1:A100").Cells
        
        cel.Replace What:=oSearch(i), Replacement:=oReplace(i)
        
      
        Next cel
        Next i
      
       
      End Sub
    so that the result will be

    F,G,H on the replace for 1,2,3


    I need to set a j somewhere?
    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,726
    Location
    Not exactly sure about what you want to do, but I don't think you need a j



    Sub Target_Array() 
         
         
        oSearch = Array(1, 2, 3) 
         
        oReplace = Array(A, B, C, D, E, F, G, H, i, j, K, L, M) 
         
        For i = LBound(oSearch) To UBound(oSearch) 
             
            For Each cel In ActiveSheet.Range("A1:A100").Cells 
                 
                cel.Replace What:=oSearch(i), Replacement:=oReplace(I+5) 
                 
                 
            Next cel 
        Next i 
         
         
    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,

    oh yes that does make sense.

    I want to replace from the 5th element onwards.

    1 > E

    2 > F

    3 >G


    my basic array replacement didint work - let me do some more experimentation
    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
  •