Read an array from a worksheet cell

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,364
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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,215,076
Messages
6,122,988
Members
449,093
Latest member
Mr Hughes

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