Changing a macro to not delete some lines

sncb

Board Regular
Joined
Mar 17, 2011
Messages
168
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Hi All..Im new to this forum and needing some assistance.

I have this section of a macro that has conditional changes such that it deletes a few lines if the 6th column is a no..Instead I want it to copy those lines and paste them into another worksheet...Below is the original code..



Application.CutCopyMode = False
For intCounter = 2 To intNoLinesFollowUp
If Cells(intCounter, 6).Value = "No" Then
Rows(intCounter).Select
Selection.Delete Shift:=xlUp
intCounter = intCounter - 1
End If
 
Last edited:
Yes..column B which is the transit number is the unique identifier for each row.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Try

Code:
Lastdate = Sheets("Test").Range("G" & Rows.Count).End(xlUp).Value
For intCounter = 2 To IntNoLinesFollowUp
If Cells(intCounter, 6).Value = "No" Then
    If IsError(Application.Match(Cells(intCounter, 2), Sheets("Test").Columns("B"), 0)) Then
        Rows(intCounter).Cut Destination:=Sheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
        Sheets("Test").Range("G" & Rows.Count).End(xlUp).Offset(1).Value = Format(Date, "dd/mm/yyyy")
        Sheets("Test").Range("H" & Rows.Count).End(xlUp).Offset(1).Value = Date - Lastdate
    End If
End If
Next intCounter
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0
When I entered this line code, I got a compile error:

"Next without for"

and the cursor went to the 3rd last line of the code
 
Upvote 0
Also for this line,

Sheets("Hold").Range("S" & Rows.Count).End(xlUp).Offset(1).Value = Date - Lastdate

I got error:

Runtime error 13

Type mismatch
 
Upvote 0
Here it is The full code



Lastdate = Sheets("Test").Range("G" & Rows.Count).End(xlUp).Value
intNoLinesFollowUp = 16
For intCounter = 2 To intNoLinesFollowUp
If Cells(intCounter, 6).Value = "No" Then
Rows(intCounter).Cut Destination:=Sheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
Sheets("Test").Range("G" & Rows.Count).End(xlUp).Offset(1).Value = Format(Date, "dd/mm/yyyy")
Sheets("Test").Range("H" & Rows.Count).End(xlUp).Offset(1).Value = Date - Lastdate
End If
Next intCounter

On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete

Range("A1").Select
 
Upvote 0
It did run but in column H it does not show no of days since ran. Im assuming since its run today probably will see '1' tomorrow in col H when I run it tomorrow.

Other than that worked liked a charm. Will report back tomorrow.

Thanks once again for ure unconditional assistance. U're great.
 
Upvote 0
It did run but in column H it does not show no of days since ran. Im assuming since its run today probably will see '1' tomorrow in col H when I run it tomorrow.


Yes, presumably it entered 0 in column H, Tomorrow it should enter 1.
 
Upvote 0
actually no..there's no '0's just a blank column H but will report back tomorrow
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,270
Members
452,902
Latest member
Knuddeluff

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