Read an array from a worksheet cell

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,368
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Right now, my process is to copy the contents of an array from the worksheet and then paste that array into the VBA.

The array is actually produced by =""""&TEXTJOIN(""", """,TRUE,IF($C$2:$C$4="Yes",$B$2:$B$4,""))&""""

I take the output and paste it into the code below. myArray(1) = Array("Year", "Month", "Day")

Instead of copying and pasting the results of TEXTJOIN as the array, can this be read straight into the code?

VBA Code:
Sub aTest()
    Dim myArray(1 To 2) As Variant
    Dim i               As Long
    Dim rng             As Range
    
    myArray(1) = Array("Year", "Month", "Day")
    myArray(2) = Array("1", "2", "3")
    
    With Sheets(1)
        For i = LBound(myArray(1)) To UBound(myArray(1))
            Set rng = .Rows(2).Find(what:=myArray(1)(i), Lookat:=xlWhole, LookIn:=xlValues, SearchOrder:=xlByColumns, MatchCase:=True)
            If Not rng Is Nothing Then
                With rng.Offset(-1)
                    .Value = myArray(2)(i)
                    .Interior.Color = vbYellow
                End With
            End If
            Set rng = Nothing
        Next i
    End With
    
End Sub
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
can you send a sample row of data and what you the Sub to do with data that matches your FIND criteria?
 
Upvote 0
Thank you Bosquedeguate, I have it straightened out now.

 
Upvote 0
In future please do not mark a post as the solution, if it does not contain one. Thanks
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top