Hui,
About a month ago you sent me a very handy vba code that recapped the occurences of zeros in a given array of numbers into one cell. So like for example an array of 1-4-0-0-0-3-4-5 would return into one cell "2-3-3"- the "2" representing the 1 and the 4, the first "3" representing the next three zeros in the array and the second "3" representing the 3,4 and 5 in the array. The formula works great and I was able to successfully apply it to my last project but now I am in need of a simmlar macro that will count negetive values along with the zeros. So where the original macro that you sent to me counted zeros vs non zeros this new one I want to count values greater than zero vs values zero and less than zero. I have pasted the original macro at the bottom of this posting.
Cheers!
Function NumbZeros(myData) As String
Dim myArr
Dim myStr As String
On Error Resume Next
count = 0
count0 = 0
myStr = ""
Set myArr = myData
For i = 1 To myData.count - 1
If myArr(i) <> 0 Then 'Data <>0
count = count + 1
If i + 1 = myData.count Then
If myArr(i + 1) = 0 Then
myStr = myStr + Str(count) + "-1"
Else
myStr = myStr + Str(count + 1)
End If
ElseIf myArr(i + 1) = 0 Then
myStr = myStr + Str(count) + "-"
count = 0
End If
Else ' Data =0
count0 = count0 + 1
If i + 1 = myData.count Then
If myArr(i + 1) = 0 Then
myStr = myStr + Str(count0 + 1)
Else
myStr = myStr + Str(count0) + "-1"
End If
ElseIf myArr(i + 1) <> 0 Then
myStr = myStr + Str(count0) + "-"
count0 = 0
ElseIf myArr(i + 1) <> 0 Then
myStr = myStr + Str(count0) + "[color 3]"
End If
End If
Next
If Right(myStr, 1) = "-" Then myStr = Left(myStr, Len(myStr) - 1)
NumbZeros = myStr
End Function
About a month ago you sent me a very handy vba code that recapped the occurences of zeros in a given array of numbers into one cell. So like for example an array of 1-4-0-0-0-3-4-5 would return into one cell "2-3-3"- the "2" representing the 1 and the 4, the first "3" representing the next three zeros in the array and the second "3" representing the 3,4 and 5 in the array. The formula works great and I was able to successfully apply it to my last project but now I am in need of a simmlar macro that will count negetive values along with the zeros. So where the original macro that you sent to me counted zeros vs non zeros this new one I want to count values greater than zero vs values zero and less than zero. I have pasted the original macro at the bottom of this posting.
Cheers!
Function NumbZeros(myData) As String
Dim myArr
Dim myStr As String
On Error Resume Next
count = 0
count0 = 0
myStr = ""
Set myArr = myData
For i = 1 To myData.count - 1
If myArr(i) <> 0 Then 'Data <>0
count = count + 1
If i + 1 = myData.count Then
If myArr(i + 1) = 0 Then
myStr = myStr + Str(count) + "-1"
Else
myStr = myStr + Str(count + 1)
End If
ElseIf myArr(i + 1) = 0 Then
myStr = myStr + Str(count) + "-"
count = 0
End If
Else ' Data =0
count0 = count0 + 1
If i + 1 = myData.count Then
If myArr(i + 1) = 0 Then
myStr = myStr + Str(count0 + 1)
Else
myStr = myStr + Str(count0) + "-1"
End If
ElseIf myArr(i + 1) <> 0 Then
myStr = myStr + Str(count0) + "-"
count0 = 0
ElseIf myArr(i + 1) <> 0 Then
myStr = myStr + Str(count0) + "[color 3]"
End If
End If
Next
If Right(myStr, 1) = "-" Then myStr = Left(myStr, Len(myStr) - 1)
NumbZeros = myStr
End Function