I'm trying to pass a dynamic array DArrayRight() between different subroutines, from DefineArrayRight (that will create the Array ) to CellRightMarked ( that will perform the action to the worksheets). Unfortunately I tried without success. Any suggestions?
Many thanks
Sub DefineArrayRight()
Dim DArrayRight() As Variant ' dynamic array
Dim xrow As Long, i As Long
i = 0
xrow = 2
ReDim DArrayRight(0) ' resize the array to hold 1 string
Do Until ThisWorkbook.Sheets("Sheet1").Cells(xrow, 2).Value = ""
If ThisWorkbook.Sheets("Sheet1").Cells(xrow, 3).Value = "Right" Then
DArrayRight(i) = ThisWorkbook.Sheets("Sheet1").Cells(xrow, 2).Value 'add the value in the array
i = i + 1 ' increase the upper bound of the array
ReDim Preserve DArrayRight(i) ' preserve the array
End If
xrow = xrow + 1
Loop
ReDim Preserve DArrayRight(i - 1) ' delete the empty array
End Sub
and pass to this sub routine:
Sub CellRightMarked()
Dim DArrayRight() As Variant
Dim rcell As Range, rrow As Range
Dim r As Integer, i As Long
For Each sht In ActiveWorkbook.Worksheets
With sht
Set rrow = .UsedRange
For r = LBound(DArrayRight) To UBound(DArrayRight)
For Each rcell In rrow
If rcell.Value = DArrayRight(r) Then
.Range(rcell.Offset(0, 1), rcell.Offset(0, 1)).Font.Color = 255
End If
Next rcell
Next r
End With
Next sht
End Sub
Sub DefineArrayRight()andSub CellRightMarked()?