+ Reply to Thread
Results 1 to 5 of 5

Storing Array to Find Replace Value via 2 Dimensional Array

Hybrid View

Matty5894 Storing Array to Find Replace... 12-15-2016, 05:50 AM
millz Re: Storing Array to Find... 12-15-2016, 06:04 AM
Matty5894 Re: Storing Array to Find... 12-15-2016, 07:55 AM
millz Re: Storing Array to Find... 12-15-2016, 09:23 PM
Matty5894 Re: Storing Array to Find... 12-19-2016, 05:53 AM
  1. #1
    Registered User
    Join Date
    06-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    78

    Storing Array to Find Replace Value via 2 Dimensional Array

    Hi All,

    Hopefully you can help.

    I have an Array

    Array1 = Array(a,b,c,d)
    Array2 = Array(1,2,3,4)

    the position between the two arrays relate ie a = 1, b = 2 and so on.

    For several Macros i need to find all the values in column A which contain Array1 and replace them to the equivalent within array2. As this action is used within multiple Macors and the Large Array occasional updates i would like to store the Array itself as a Public Function to call upon ie.

    Formula: copy to clipboard

    Public Function Replace(Array As String)

    Select Case Array

    Case Is = "ArrayOne"
    Replace = Array("a", "b", "c", "d")

    Case Is = "ArrayTwo"

    Replace = Array("1", "2", "3", "4")

    End Select

    End Function



    This would call within the Macro as follows

    Formula: copy to clipboard

    For Each t In Replace("ArrayOne")
    Columns("A").Replace What:=t, Replacement:= (Array 2 But How), LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Next t


    Any help which can be provided would be great!

    Cheers

  2. #2
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Storing Array to Find Replace Value via 2 Dimensional Array

    Maybe this?
    Dim Array1, Array2, i As Long
    Array1 = Array("a", "b", "c", "d")
    Array2 = Array("1", "2", "3", "4")
    
    For i = LBound(Array1) To UBound(Array1)
        Columns("A:A").Replace What:=Array1(i), Replacement:=Array2(i), LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
    Next
    多么想要告诉你 我好喜欢你

  3. #3
    Registered User
    Join Date
    06-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    78

    Re: Storing Array to Find Replace Value via 2 Dimensional Array

    Thanks, the above works however only when all within one Macro.

    Ideally i require the below as a public function to call upon

    Formula: copy to clipboard

    Dim Array1, Array2, i As Long
    Array1 = Array("a", "b", "c", "d")
    Array2 = Array("1", "2", "3", "4")


    Therefore the below would be within each of my individual Macros

    Formula: copy to clipboard

    Call Public Function

    For i = LBound(Array1) To UBound(Array1)
    Columns("A:A").Replace What:=Array1(i), Replacement:=Array2(i), LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
    Next


    Is this achievable at all?

    Cheers

  4. #4
    Forum Expert millz's Avatar
    Join Date
    08-14-2013
    Location
    Singapore
    MS-Off Ver
    Excel, Access 2016
    Posts
    1,694

    Re: Storing Array to Find Replace Value via 2 Dimensional Array

    Hi, you can declare them as public variables, then initialize them with a separate function.
    Public Array1, Array2
    
    Function InitArrays()
        Array1 = Array("a", "b", "c", "d")
        Array2 = Array("1", "2", "3", "4")
    end function
    
    Sub main()
        Dim i As Long
        Call InitArrays
    
        For i = LBound(Array1) To UBound(Array1)
            Columns("A:A").Replace What:=Array1(i), Replacement:=Array2(i), LookAt:=xlPart, _
            SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
            ReplaceFormat:=False
        Next
    end sub

  5. #5
    Registered User
    Join Date
    06-23-2014
    Location
    england
    MS-Off Ver
    2013
    Posts
    78

    Re: Storing Array to Find Replace Value via 2 Dimensional Array

    Works Perfect! Thank you very much

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help converting one-dimensional array to multi-dimensional array
    By puzzlelover22 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-13-2016, 06:48 AM
  2. Parse Data from one dimensional array into a 2 dimensional array.
    By JapanDave in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-30-2016, 07:29 AM
  3. [SOLVED] Convert one dimensional array into two dimensional array
    By mohammed sabr in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-26-2015, 10:34 AM
  4. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  5. Populate a Single Dimensional Array with two Dim Array (matrix)
    By Benjamin1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-03-2011, 12:49 PM
  6. [SOLVED] Mutli-dimensional Array to Single-Dimension Array
    By Blue Aardvark in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-15-2005, 05:05 AM
  7. [SOLVED] Create One-Dimensional Array from Two-Dimensional Array
    By Stratuser in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-23-2005, 05:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1