I've been able to search the worksheet for a name (Dion in the code below) and copy the row containing the name Dion to a different worksheet. However, the destination worksheet may contain text in the columns adjacent to, and beyond, the last column of text in the source worksheet.
I want to be able to select a range of cells from the row containing Dion, with the selection ending at a cell containing specific text.
I also tried changing If Cells(...).Value = "Dion" Then
to
If Range("A1:CS1000")...
but kept getting a Type Mismatch error.
Here is my VBA code. I know it's probably very inefficient, but it's what I was able to make work:
Dim r As Long
Dim endRow As Long
Dim pasteRowIndex As Long
Worksheets("Tracking").Activate
endRow = 500
pasteRowIndex = 1
For r = 6 To endRow
If Cells(r, Columns("BM").Column).Value = "Dion" Then
Rows(r).Select
'Code above shoud select all cells from Rows(r) until a cell contains the text "End"
Selection.Copy
Worksheets("Dion").Select
Rows(pasteRowIndex + 5).Select
ActiveSheet.Paste
pasteRowIndex = pasteRowIndex + 1
Worksheets("Tracking").Select
End If
Next r
Thanks for your help.
Cells(r, Columns("BM").Column)
you can simply sayCells(r, "BM")
– A.S.H