VBA code to duplicate select info

Ashe77

New Member
Joined
May 23, 2013
Messages
13
Hello all

I wonder if anyone could help me with some VBA please, I have a worksheet (named ProjectTimeline) that has various criteria in a table (columns A to P) that feeds some pivottables which then feeds a line chart. I'd like to be able to use a macro to copy the whole worksheet to a new sheet BUT exclude any entries that have a "no" in column Q.

Is this possible or am I extravagantly dreaming?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
if you know how to copy a sheet to a new worksheet, why don't you don't you flip flop your logic. Copy the entire sheet, and then on the new sheet delete any rows where Column Q = "no".
 
Upvote 0
Does this work:

Code:
Sub NoNos()


    Dim ws As Worksheet: Set ws = Worksheets("ProjectTimeline")
    Dim lRow As Long, i As Long
    
    Application.ScreenUpdating = False
    ws.Copy after:=Worksheets(ThisWorkbook.Worksheets.Count)
    lRow = Cells(Rows.Count, "Q").End(xlUp).Row
    For i = lRow To 2 Step -1
        If Cells(i, 17) = "no" Then Cells(i, 17).EntireRow.Delete
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Sir the code was PERFECT, thank you so much. :biggrin:



Does this work:

Code:
Sub NoNos()


    Dim ws As Worksheet: Set ws = Worksheets("ProjectTimeline")
    Dim lRow As Long, i As Long
    
    Application.ScreenUpdating = False
    ws.Copy after:=Worksheets(ThisWorkbook.Worksheets.Count)
    lRow = Cells(Rows.Count, "Q").End(xlUp).Row
    For i = lRow To 2 Step -1
        If Cells(i, 17) = "no" Then Cells(i, 17).EntireRow.Delete
    Next
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
I was happy to help. Thanks for the feedback!
 
Upvote 0

Forum statistics

Threads
1,215,035
Messages
6,122,785
Members
449,095
Latest member
m_smith_solihull

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