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:
Try like this

Rich (BB code):
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)
End If
Next intCounter
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Thanks Vog..it works like a charm...ure a genius man :)

I however need to add just one last detail. on the 'test' sheet, on let's say cell G2 and all rows below till the last record, I need to have the macro run date and no of days since it last ran on H2 and all records below.....the no of days since last run is not very imp but the run date definitely is..

Any suggestions...Thanks once again..
 
Upvote 0
Try

Rich (BB code):
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")
End If
Next intCounter
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0
Hi Vog,

your code did add the date but only on the first row (in cell G2) but not for any other records below...
 
Upvote 0
I've just run it and it did

Excel Workbook
ABCDEFG
2101448No18/03/2011
379855No18/03/2011
410471010No18/03/2011
Test
 
Upvote 0
Oh yeah..it did run...but for some reason not all the way through to the last record..stopped somewhere in between ..but all in all THANKS a million Vog....logging off for the day... salute!!
 
Upvote 0
Hi Vog,

could you explain what would be the meaning of this part of the code:

intNoLinesFollowUp = 16
For intCounter = 2 To intNoLinesFollowUp

Thanks
 
Upvote 0
got it. Thanks..

if you remember in the new tab 'Test' in column G we had the run date, in which case I see today's date with lets say 10 records create(G2 to G11)

But let's say tomorrow I return and run the macro again I need the newest records created from G12 onwards with tomorrow's date beside it but only if they do not occur in G2-G11 from previous runs...(is this even possible?)

Finally in column H, what code do I need to add to have the no of days since the last run was made...

Thanks a lot Vog..uve been really supportive.
 
Upvote 0
For the first question, is there a unique identifier in any column that we could check in both sheets?

For the second try

Code:
Lastdate = Sheets("Test").Range("G" & Rows.Count).End(xlUp).Value
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
 
Upvote 0

Forum statistics

Threads
1,224,520
Messages
6,179,266
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