Macro to find all negative values in a column and paste the rows to a new sheet

hinch42

New Member
Joined
Feb 23, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for a macro that can find all negative values in a column and then copy the row associated with the negative column value and past into a new worksheet in the same work book. The data is for accounting purposes. The column in question is "P" which are days late. When the days are negative that means they are late so I need to find a way to select rows which have late days present. I'm hoping to eventually automate the macro through power automate but that is next weeks battle.

Thank you all! Enjoying the forum, it is a great resource.
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Hi and welcome to MrExcel

Try this:

VBA Code:
Sub copyrows()
  Dim sh1 As Worksheet
  Set sh1 = Sheets("Sheet1")    'fit to the name of your sheet
  
  If sh1.AutoFilterMode Then sh1.AutoFilterMode = False
  sh1.Range("A1:P" & sh1.Range("P" & Rows.Count).End(3).Row).AutoFilter 16, "<0"
  sh1.AutoFilter.Range.Copy
  Sheets.Add , Sheets(Sheets.Count)
  ActiveSheet.Range("A1").PasteSpecial xlPasteValues
  sh1.ShowAllData
End Sub
 
Upvote 0
Solution
Hi and welcome to MrExcel

Try this:

VBA Code:
Sub copyrows()
  Dim sh1 As Worksheet
  Set sh1 = Sheets("Sheet1")    'fit to the name of your sheet
 
  If sh1.AutoFilterMode Then sh1.AutoFilterMode = False
  sh1.Range("A1:P" & sh1.Range("P" & Rows.Count).End(3).Row).AutoFilter 16, "<0"
  sh1.AutoFilter.Range.Copy
  Sheets.Add , Sheets(Sheets.Count)
  ActiveSheet.Range("A1").PasteSpecial xlPasteValues
  sh1.ShowAllData
End Sub

[
[/QUOTE]
That worked, thank you!
 
Upvote 1

Forum statistics

Threads
1,215,043
Messages
6,122,812
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