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:
Hi Vog,

So here's what has happened. In column 'G' I get today's date but in 'H' I get 3/22/2011

So here's how it looks:

G H
22/03/2011 3/22/2011
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Sorry, it is obviously not picking up the correct value for Lastdate but I don't know why. I think you'll have do do without this 'feature'. It should be easy enough to spot the number of days since the last run by scanning column G.
 
Upvote 0
Yeah, i guess Ill do without it. I'll just look at the dates.

But regarding adding new records to the tab 'Test' for new dates like today after the last record of the previous date, that's not happening.

What I'm doing is opening the original document and running it for today due to which I'm getting only today's records. If I use yesterday' saved document it dosen't update records from today. It just stays the same as if nothing happened.

Something not related directly to this: This macro code has about 5 steps of which this is step 4. For example if I need to add another step between 4 and 5 but without writing code and just doing the process itself(like recording the macro) whats the way to proceed?

Thanks once again.
 
Upvote 0
Don't forget that we added code to prevent the same record being transferred again.
 
Upvote 0
Hi Vog,

I get it.

But I need to add new records that ran today after the last record for the previous day and so on and so forth. That's not happening. Any suggestions?

Current 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")

End If
End If
Next intCounter
On Error Resume Next
Columns("A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
 
Upvote 0
I made a small change

Rich (BB code):
Sub atest()
Dim IntCounter As Long, IntNoLinesFollowUp As Long, LastDate As Date
IntNoLinesFollowUp = 16
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
End Sub

My results: I added the row in blue to ensure I had a date in column G. Then I ran the code. Then I ran the code again (row in red). These results look correct to me.

Excel Workbook
ABCDEFGH
111111114/03/2011
2481773753No22/03/20118
3536844842No22/03/20118
46629343263No22/03/20118
53988986344No22/03/20110
Test
 
Upvote 0
I copied the code exactly and I get the following compile error

'Duplicate declaration in current scope'

pointing to:

IntCounter As Long
 
Upvote 0
Just click anywhere in the code window, press CTRL + A, then CTRL + C, then come here and press CTRL + V.
 
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