![]() |
|
#1
|
|||
|
|||
|
I have a cell that has multiple values, separated by ";". For example: "35; 255; 67; 0". In the next cell, I would like to know how can I count these values, except zero. Count not SUM them. This single cell, can have up to 50 values and each value can have up to 7 digits. I have looked up for COUNT, COUNTA, COUNTIF functions but didn't find any relevancy to what I'm trying to do. Can you, please help me? |
|
#2
|
||||
|
||||
|
Hi iuliandonici,
Assuming this is just an additional requirement to what was in your other thread: Code:
Sub InOut()
Application.ScreenUpdating = False
Dim StrIn As String, StrOut As String, i As Long, k As Long
Dim StrSub As String, StrAdd As String, j As Long, l As Long
With ActiveSheet()
For i = 7 To .Range("C" & .Rows.Count).End(xlUp).Row
StrAdd = ""
StrSub = ""
k = 0
l = 0
StrIn = Trim(Replace(.Cells(i, 3).Value, ";", ""))
StrOut = Trim(Replace(.Cells(i, 4).Value, ";", ""))
If UBound(Split(StrIn, " ")) = UBound(Split(StrOut, " ")) Then
For j = 0 To UBound(Split(StrIn, " "))
StrAdd = StrAdd & CLng(Split(StrIn, " ")(j)) + CLng(Split(StrOut, " ")(j)) & " "
StrSub = StrSub & CLng(Split(StrIn, " ")(j)) - CLng(Split(StrOut, " ")(j)) & " "
If Split(StrIn, " ")(j) <> 0 Then k = k + 1
If Split(StrOut, " ")(j) <> 0 Then l = l + 1
Next
StrAdd = Replace(StrAdd, " ", "; ")
StrSub = Replace(StrSub, " ", "; ")
Else
StrAdd = "IN/OUT item counts differ"
StrSub = "IN/OUT item counts differ"
End If
.Cells(i, 5).Value = StrAdd
.Cells(i, 6).Value = StrSub
.Cells(i, 7).Value = k
.Cells(i, 8).Value = l
Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Tags |
| count multiple, multiple values, single cell |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Sum & difference between multiple values in a single cell
|
iuliandonici | Excel | 4 | 04-13-2011 09:27 PM |
Count with multiple conditions
|
bundy5150 | Excel | 4 | 02-22-2011 10:00 AM |
How can I write the following (whole) formula in a single cell?
|
Learner7 | Excel | 1 | 07-19-2010 10:06 AM |
| Pasting multiple photos - one photo per cell in a single oepration | mccruise | Word | 0 | 04-07-2010 04:13 AM |
| multiple colums under a single column | RobotChicken | Excel | 3 | 01-06-2010 09:17 AM |