Results 1 to 8 of 8

Thread: Offset based on Values in Column E

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try something like this.

    Code:
    Sub kTest()
        
        Dim i As Long, j As Long, r As Range, ff As String
        Dim SearchKeys1, SearchKeys2, SearchKeysAll, Replacement
        
        SearchKeys1 = Array("Open", "Received")
        SearchKeys2 = Array("Approved", "Disassemble")
        
        SearchKeysAll = Array(SearchKeys1, SearchKeys2)
        
        Replacement = Array("Gate 1", "Gate 2")
        
        With Intersect(ActiveSheet.UsedRange, Columns(5))
            For i = LBound(Replacement) To UBound(Replacement)
                For j = LBound(SearchKeysAll(i)) To UBound(SearchKeysAll(i))
                    Set r = .Find(SearchKeysAll(i)(j), lookat:=2)
                    If Not r Is Nothing Then
                        ff = r.Address
                        Do
                            Set r = .FindNext(r)
                            r.Offset(, 4) = Replacement(i)
                        Loop Until r.Address = ff
                    End If
                Next
            Next
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  2. #2
    Member mrmmickle1's Avatar
    Join Date
    Sep 2012
    Posts
    51
    Rep Power
    14
    Admin,

    Thanks so much. I modified it by adding more search keys and got it to work for my needs! I appreciate the help. Here is my Final Product:

    Code:
    
    Sub GroupStatusbyInsertingUniqueValue()
        
        Dim i As Long, j As Long, r As Range, ff As String
        Dim SearchKeys1, SearchKeys2, SearchKeys3, SearchKeys4, SearhKeys5, SearchKeys6, _
        SearchKeys7, SearchKeys8, SearchKeys9, SearchKeys10, SearchKeysAll, Replacement
        
        SearchKeys1 = Array("Open", "Received", "Preliminary Ins", "Pre Test", "Insp-APU")
        SearchKeys2 = Array("Approved", "Disassemble", "RETURN AS IS", "Waiting Parts", "Waiting Compone", "Assembly", _
        "Test", "Post Test", "QEC", "QC", "QC Discrepancy", "Shipping Prep", "Assembly-APU")
        SearchKeys3 = Array("Clean")
        SearchKeys4 = Array("Inspection")
        SearchKeys5 = Array("Customer Servic")
        SearchKeys6 = Array("Lease")
        SearchKeys7 = Array("Quote on Hold", "Quote")
        SearchKeys8 = Array("Closed", "Invoicing")
        SearchKeys9 = Array("Parking Lot")
        SearchKeys10 = Array("Waiting App.")
        
        
        SearchKeysAll = Array(SearchKeys1, SearchKeys2, SearchKeys3, SearchKeys4, SearchKeys5, _
        SearchKeys6, SearchKeys7, SearchKeys8, SearchKeys9, SearchKeys10)
        
        Replacement = Array("GATE 1", "GATE 2", "GATE 3", "GATE 4", "CUSTOMER SERVICE", "LEASE", "QUOTE", "SHIPPED", "SURPLUS PARTS", "WAITING APPROVAL")
        
        With Intersect(ActiveSheet.UsedRange, Columns(4))
            For i = LBound(Replacement) To UBound(Replacement)
                For j = LBound(SearchKeysAll(i)) To UBound(SearchKeysAll(i))
                    Set r = .Find(SearchKeysAll(i)(j), lookat:=2)
                    If Not r Is Nothing Then
                        ff = r.Address
                        Do
                            Set r = .FindNext(r)
                            r.Offset(, 10) = Replacement(i)
                        Loop Until r.Address = ff
                    End If
                Next
            Next
        End With
        
    End Sub
    Using Excel 2010

Similar Threads

  1. Replies: 10
    Last Post: 05-23-2013, 12:30 PM
  2. Replies: 17
    Last Post: 05-22-2013, 11:58 PM
  3. How to make Dynamic range (width) with OFFset function
    By Rajesh Kr Joshi in forum Excel Help
    Replies: 12
    Last Post: 12-01-2012, 11:03 PM
  4. Group Pivot Data Based On Row Values In One Column
    By mrmmickle1 in forum Excel Help
    Replies: 10
    Last Post: 10-09-2012, 11:46 PM
  5. Replies: 3
    Last Post: 08-05-2012, 09:16 PM

Posting Permissions

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