VBA for separating out negative values, and figuring out the ‘most negative’ in each run of negative numbers

I have a macro that I generated several years ago with help of some on here, at the time the purpose of the macro was to extract all negative values from a couple of columns, and put them into a graph, highlighting the most negative value.

The numbers were generated from a machine that indents a material. This records the force with positive values meaning the machine is pushing and negative values meaning the machine is trying to pull away (so the adhesive force of the substrate).

Now the new kit will indent multiple times, so there will be a run of positive numbers, a run of negative numbers and this will repeat 4-5 times.

The previous macro extracts ALL the negative values and graphs them, only pulling out the MAX negative value, however it would be useful to isolate all of these “Adhesive events” separately, for example:

Eventually the ‘Force’ column turns positive (not shown in image as it’s quite a lot of readings) then it will repeat and turn negative again, I need to extract each of these negative runs separately, my previous macro would only summarise all negative values and not separate out each of the ‘runs’

I presume there will be a way to select negative numbers in VBA until you hit a positive, then graph that (or extract lowest value) and carry on until the next range of negatives,

Sub CopyAndGraphFinal()

‘ CopyAndGraph Macro

Dim Actwks As Worksheet

Set Actwks = ActiveSheet

Application.ScreenUpdating = False

‘Dont update screen while running (lags a bit)

For Each Actwks In Worksheets

Actwks.Activate

‘Do for every sheet in the Book

Range("A5427").Select

Selection.End(xlUp).Select

Range(Selection, Selection.End(xlUp)).Select

‘Select last A Column

Selection.Copy

Range("H4").Select

ActiveSheet.Paste

‘Paste in H4

Range("B5569").Select

Selection.End(xlUp).Select

Range(Selection, Selection.End(xlUp)).Select

Application.CutCopyMode = False

Selection.Copy

‘Select and Paste B Column

Range("I4").Select

ActiveSheet.Paste

Range("H4:I2002").Select

Range("I4").Activate

Range("H3:I3").Select

Application.CutCopyMode = False

Selection.AutoFilter

ActiveSheet.Range("H3:I3002").AutoFilter Field:=1, Criteria1:=">0", _

    Operator:=xlAnd

ActiveSheet.Range("H3:I3002").AutoFilter Field:=2, Criteria1:="<0", _

    Operator:=xlAnd

‘Filter for >0 and <0

Range("J5:J2500").Formula = "=(RC[-1]+R[1]C[-1])/2*(R[1]C[-2]-RC[-2])"



ActiveSheet.Shapes.AddChart2(240, xlXYScatterLines).Select

ActiveChart.SetSourceData Source:=Range("H:I")



Range("L1").Select

ActiveCell.FormulaR1C1 = "Total Adhesive Energy"

Range("L2").Select

ActiveCell.FormulaR1C1 = "Peak Force"

Range("M1").Select

ActiveCell.FormulaR1C1 = "=SUBTOTAL(9,C[-3])"

Range("M2").Select

ActiveCell.FormulaR1C1 = "=MIN(C[-4])"

Range("M3").Select



Next Actwks

Application.ScreenUpdating = True

Any help would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật