Approach To Continue a Loop From an If / Then condition

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,570
Office Version
  1. 365
  2. 2016
Platform
  1. 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!

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
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
let me rephrase your logic, because one thing isn't clear:

  1. Target_C not W* -> copy Source_row to Target_row
  2. Target_C is W* AND Source_C <> "" -> leave Target_row unchanged
  3. Target_C is W* AND Source_C = "" -> ???
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,623
Latest member
Techenthusiast

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top