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:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Try

Code:
Dim IntNoLinesFollowUp As Long, LastDate As Date
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 = Date
        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
Same error:

'Duplicate declaration in current scope'

but now pointing to:

IntNoLinesFollowUp
 
Upvote 0
Try

Code:
Dim LastDate As Date
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 = Date
        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
Whew!!! that ran....But I guess I can check for new record creation only tomorrow and later. So I'll post accordingly.

No more words left to say Thanks.
 
Upvote 0
This came out of the blue. On debugging I get this:

Runtime error 13

'Type Mismatch'



pointing to:

LastDate = Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value
 
Upvote 0
Don't know what exactly you mean by excel date, but I did enter today's date 22/03/2011 on cell R65536 but still gives the same error:

Runtime error 13

'Type Mismatch'

and point to the same line of code.
 
Upvote 0
Try

Code:
If IsDate(Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value) Then
    LastDate = Sheets("Hold").Range("R" & Rows.Count).End(xlUp).Value
Else
    LastDate = Date
End If
 
Upvote 0
happy to report that it worked with no debugging issues. now to wait till tomorrow when I run it again to see if it adds new records after the last one from today.

Sending you PM of the whole code for that step.

Thanks
 
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,283
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