Hi,
I have this that should take the column and check if each value are greater than mx, if so then subtract bl from them and return them in new column. Then check them again and if Value is smaller than bl then change that value to bl and return in next column.
but it doesn't work and I keep getting "Invalid use of a property" error.
p.s. str supposted to count how many values are greater than mx.
Private Sub CommandButton1_Click()
Dim bl As Long
Dim mx As Long
Dim pw As Range
Dim LastColumn As Long
Dim str As Long
Dim pkSh As Long
LastColumn = ActiveSheet.Cells.Find("*", SearchOrder:=xlByColumns, SearchDirection:=xlPrevious).Column + 1
str = 0
mx = TextBox_maxP * TextBox_PeakS / 100
bl = TextBox_maxP * TextBox_baseL / 100
Set pw = UsedRange.Find("Power", , , 1, 1).Columns
With Range(pw, pw.End(xlDown))
If .Value >= mx Then .Value -bl
str = str + 1
ElseIf .Value < bl Then .Value = bl
End If
End With
Next
.Range("peak shaving" & LastColumn + 1) = pkSh
.Range("battery" & LastColumn + 2) = .Value
Range("K1").Value = str
End Sub
Bookmarks