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

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.
Hi. Try like this

Code:
Application.CutCopyMode = False
For intCounter = 2 To intNoLinesFollowUp
If Cells(intCounter, 6).Value = "No" Then
    Rows(intCounter).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next intCounter
 
Upvote 0
nops..that didn't work...any more info you would need?
 
Upvote 0
no..nothing happened..i named the new sheet as 'Test' and renamed the 'Sheet2' to 'Test' in the code

the process ran like usual but the removed records did not show up in the 'Test' sheet
 
Upvote 0
This worked for me. The sheet with No in column F must be selected before running

Code:
Sub atest()
Dim intCounter As Long, IntNoLinesFollowUp As Long
IntNoLinesFollowUp = 16
For intCounter = 2 To IntNoLinesFollowUp
If Cells(intCounter, 6).Value = "No" Then
    Rows(intCounter).Copy Destination:=Sheets("Test").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next intCounter
End Sub
 
Upvote 0
here is the full original code..I believe the last line is not relevant to this process, but the next....just assuming..could be wrong


intNoLinesFollowUp = WorksheetFunction.CountA(Sheets("FollowUp").Range("A:A"))
intCounter = 0

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
Next intCounter
Range("A1").Select
 
Upvote 0
Hi Vog,

Thanks for earlier help.

However one question..after changing the logic from deleting to making a copy in the new 'test' sheet, the original records in the 1st sheet still exist. I tried changing the copy to cut but its leaving the rows blank. Is there a way to remove the blank rows after they are removed from the original sheet.

Thanks once again

 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,253
Members
452,900
Latest member
LisaGo

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