PDA

View Full Version : [SOLVED:] Filter columns from negative values for Histogram Chart



cabete
03-31-2016, 10:49 AM
Hello every one.
I have a sheet (sheet1)that are caming new values to the column A every 30 seconds, this cane goes to 1300 value witch 8 hours, this value sometime came negative.

I want make a histogram chart and this negative values make my chart NOK.

There anyone could help me to get a formula to filter just the possitive value without blanck line beetwen

p45cal
03-31-2016, 01:54 PM
Advanced Filter will do the trick. In the attached file I've set up a criterion range for advanced filter in sheet1 cells C1:C2 to filter for cells >=0 and place the results in Chart cells C4 and below.
The advanced filter can be written as a one-line macro:

Sub blah()
Sheets("Sheet 1").Columns("A:A").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=Sheets("Sheet 1").Range("C1:C2"), CopyToRange:=Sheets("Chart").Range("C4"), Unique:=False
End Sub
On the Chart sheet I've placed a button in the vicinity of cell Q20 which runs this macro.
Instead of clicking a button, the macro can be run automatically each time the data in sheet1 changes.

There probably is a formula that you can use in column C of Chart but it would be quite resource-hungry. I will explore this.

p45cal
03-31-2016, 02:29 PM
There probably is a formula that you can use in column C of Chart but it would be quite resource-hungry. I will explore this.
This is for you to check, but looking at the way you calculate values and chart series, it may be that you can have blank cells between positive values.
Try in cell C5:

=IF(AND('Sheet 1'!A2>=0,'Sheet 1'!A2<>""),'Sheet 1'!A2)
and copy down as far as you feel will ever be necessary.
Perhaps also check:
=IF(AND('Sheet 1'!A2>=0,'Sheet 1'!A2<>""),'Sheet 1'!A2,"") which will show blank rows instead of 'FALSE'.
This approach (if it gives the right results) would probably be simpler than, and preferable to, my earlier solution, without being especially resource-hungry.

cabete
03-31-2016, 02:36 PM
Its perfect.
anyway i find also a solution.

Option Explicit'--------->>
Public Sub DeleteRange()
Dim WB As Workbook
Dim SH As Worksheet
Dim Rng As Range, rCell As Range, delRng As Range
Dim LRow As Long
Dim CalcMode As Long


Set WB = ThisWorkbook
Set SH = WB.Sheets("Folha1")


With SH
LRow = .Cells(.Rows.Count, "a").End(xlUp).Row
Set Rng = .Range("a2:B" & LRow)
End With


With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With


For Each rCell In Rng.Cells
With rCell
If IsNumeric(.Value) And .Value < 0 Then
If delRng Is Nothing Then
Set delRng = rCell
Else
Set delRng = Union(rCell, delRng)
End If
End If
End With
Next rCell


If Not delRng Is Nothing Then
delRng.EntireRow.Delete
End If


With Application
.Calculation = CalcMode
.ScreenUpdating = True
End With
End Sub


But this its much more simple

p45cal
03-31-2016, 02:41 PM
Did you see my update (msg#3)?