Ark68
Well-known Member
- Joined
- Mar 23, 2004
- Messages
- 4,616
- Office Version
- 365
- 2016
- Platform
- Windows
I have two worksheets, ws_source and ws_target.
The basic idea of what I'm trying to do is to copy a range of data from ws_source to ws_target. Normally it would be simple enough to copy the range and paste it to the same range in ws_target.
However, there may be rows of data in that destination row than cannot be copied over. If any cell in column c of the target worksheet contains a value beginning with "W", it must remain in place and not be copied over with the transerring range.
If the cell at column c of that row doesn't begin with a "W", the code simply copies the range C:F from the source that same row in the target worksheet.
Now, if the value in cell c and the row being inspected begins with a "W", that same cell reference is checked in the source worksheet. If the value in column c of that row isn't blank, then that range in the target worksheet remains the same. The code can resume with the next i.
I hope I make sense. My code isn't working the way I need it to. It's likely the wrong approach. Any help would be greatly appreciated!
ws_target is the recognized target worksheet, ws_source is the recognized source date. Data is being copied from the source to the target.
i is the row number between a variable start row (rw_date) and row 365
The basic idea of what I'm trying to do is to copy a range of data from ws_source to ws_target. Normally it would be simple enough to copy the range and paste it to the same range in ws_target.
However, there may be rows of data in that destination row than cannot be copied over. If any cell in column c of the target worksheet contains a value beginning with "W", it must remain in place and not be copied over with the transerring range.
If the cell at column c of that row doesn't begin with a "W", the code simply copies the range C:F from the source that same row in the target worksheet.
Now, if the value in cell c and the row being inspected begins with a "W", that same cell reference is checked in the source worksheet. If the value in column c of that row isn't blank, then that range in the target worksheet remains the same. The code can resume with the next i.
I hope I make sense. My code isn't working the way I need it to. It's likely the wrong approach. Any help would be greatly appreciated!
Rich (BB code):
For i = rw_date To 365
If ws_target.Cells(i, 3) Like "W*" Then 'te employee has previously booked this day off,do not replace if par tof new schedule
If ws_source.Cells(i, 3) <> "" Then do nothing but carry on with the loop
Else
ws_source.Range("C" & i & ":F" & i).Copy Destination:=ws_target.Range("C" & i)
End If
Next i
ws_target is the recognized target worksheet, ws_source is the recognized source date. Data is being copied from the source to the target.
i is the row number between a variable start row (rw_date) and row 365