Try this
Sub Grab_Shift()
Dim dRef As String, rng As Range, ws1 As Worksheet
Dim x As Long, y As Long, ff As String, PasteTo As Range
Dim strRng
Dim intLast As Integer
Dim intFirst As Integer
Dim intRow As Integer
dRef = "Rotating"
Set rng = Sheets("MSF").Range("NamenShift")
Set ws1 = Sheets("Sheet1")
''if you dont already have something in B6 on sheet 1 then set a header in B5 so that your new data starts at B6
ws1.Cells(5, 2).Value = "New Data"
''find the column to be used for copying data (last column)
strRng = rng.Address(ReferenceStyle:=xlR1C1)
intLast = Mid(strRng, InStrRev(strRng, "C") + 1)
''mark the first column to exclude this if the search valve (Rotating) is found
intFirst = Mid(strRng, InStr(strRng, "C") + 1, (InStr(strRng, ":") - 1) - (InStr(strRng, "C")))
x = rng.Rows.Count
y = rng.Columns.Count
Set cell = rng.Find(dRef, rng.Cells(x, y), , xlWhole)
If Not cell Is Nothing Then
ff = cell.Address
Do
''this allows you to write to a specific row
intRow = ws1.Cells(Rows.Count, "B").End(xlUp).Row + 1
''make sure we are not looking at the first column
If cell.Column > intFirst Then
Worksheets("Sheet1").Cells(intRow, 2).Value = Worksheets("MSF").Cells(cell.Row, intLast).Value
End If
Set cell = rng.FindNext(cell)
Loop While cell.Address <> ff
End If
Set ws1 = Nothing: Set rng = Nothing
Set cell = Nothing: Set PasteTo = Nothing
End Sub
Bookmarks