Hi
The context, I have worksheet Costa Rica where I select data based on a multiple criteria (array) and copy it to workshet March, I was able to built in a code that partially works...because what I need is that the paste is done up to final active cell on column A of Worshet March on every copy and not replacin existing data.
So, basically I need to replace the ActiveSheet.Paste line (the only one I was able to work with) and I already tried ActiveCell.Offset but it didn't work...any other idea is more than welcome.
Any help kindly appreciated
The context, I have worksheet Costa Rica where I select data based on a multiple criteria (array) and copy it to workshet March, I was able to built in a code that partially works...because what I need is that the paste is done up to final active cell on column A of Worshet March on every copy and not replacin existing data.
So, basically I need to replace the ActiveSheet.Paste line (the only one I was able to work with) and I already tried ActiveCell.Offset but it didn't work...any other idea is more than welcome.
Any help kindly appreciated
Rich (BB code):
Sub SearchForString()
Dim LSearchRow As Integer
Dim LCopyToRow As Integer
Dim ArrayCo As Variant
Dim I As Integer
'Start search in row 4
LSearchRow = 3
'Start copying data to row 2 in Month (row counter variable)
LCopyToRow = 2
While Len(Range("A" & CStr(LSearchRow)).Value) > 0
ArrayCo = Array("GL60", "GL62", "GL67", "GL69", "GL72", "GL75", "GL85", "GL86", "GL87", "GL88", "EBILLING60")
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 row in Costa Rica to copy
Rows(CStr(LSearchRow) & ":" & CStr(LSearchRow)).Select
Selection.Copy
'Paste row into March in next row
Sheets("March").Select
Rows(CStr(LCopyToRow) & ":" & CStr(LCopyToRow)).Select
ActiveSheet.Paste
'Move counter to next row
LCopyToRow = LCopyToRow + 1
'Go back to Costa Rica to continue searching
Sheets(" Costa Rica").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
End Sub
Last edited by a moderator: