Hi
I'm used the code below in the past to select from a set of an array (same variables) to copy / paste into the last line it works as it suppose to do it. Nevetheless now the one single rule change, I have to choose from a set of variables within the same range, where the variables are defined each time by the user, meaning it changes each time. So I try to built in the array based on values on a specific range in Sheets(1) and even when it doesn't trigger an error it doesn't execute what is expected (copy / paste) based on the array. I'm highlighting in red the part code that I think needs to be change, but I don't know how...so any help is more than welcome.
I'm used the code below in the past to select from a set of an array (same variables) to copy / paste into the last line it works as it suppose to do it. Nevetheless now the one single rule change, I have to choose from a set of variables within the same range, where the variables are defined each time by the user, meaning it changes each time. So I try to built in the array based on values on a specific range in Sheets(1) and even when it doesn't trigger an error it doesn't execute what is expected (copy / paste) based on the array. I'm highlighting in red the part code that I think needs to be change, but I don't know how...so any help is more than welcome.
Code:
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim ArrayCo As Variant
Dim I As Integer
'On Error GoTo Err_Execute
'Start search in row 4
LSearchRow = 3
'Start copying data to row 2 in Sheet2 (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
[B][COLOR=red]ArrayCo = Application.Transpose(Sheets(1).Range("B2:B12").Value)[/COLOR][/B]
Application.ScreenUpdating = False
For I = 0 To UBound(ArrayCo)
'If value in column A = ArrayCo and Invoice Coding And PO Redistribution, copy entire row to Sheet2
If Range("A" & CStr(LSearchRow)).Value = ArrayCo(I) And _
Range("H" & CStr(LSearchRow)).Value = "Invoice Coding" Or _
Range("A" & CStr(LSearchRow)).Value = ArrayCo(I) And _
Range("H" & CStr(LSearchRow)).Value = "PO Redistribution" Then
'Select Copy from Doxis Costa Rica
Sheets(3).Select
Range(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Copy
'Select Destination to Paste
Sheets(2).Select
NextRow = Cells(Rows.Count, 1).End(xlUp).Row + 1
Cells(NextRow, 1).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Costa Rica to continue searching
Sheets(3).Select
End If
LSearchRow = LSearchRow + 1
Next I
Wend
'Position on cell A3
Application.CutCopyMode = False
Range("A3").Select
MsgBox "All matching data has been copied."
Exit Sub
'Err_Execute:
'MsgBox "An error occurred."
End Sub