ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Code not working as expected. (https://www.excelbanter.com/excel-discussion-misc-queries/188065-code-not-working-expected.html)

Ayo

Code not working as expected.
 
I have a snippet of a code shown below, when
c.value=3 and c1.value= "Cluster 3", i is still showing zero. I can't
figut=re out what is going on here. The only thing I noticed is that c.values
are double and c1.values are strings. I don't know if that makes any
difference.
Please help.

For Each c1 In Worksheets(1).Range("A39:A46").Cells
i = 0
For Each c In clusterRange.Cells
If c.Value = Mid(c1.Value, 9) Then
i = i + 1
End If
Next c
c1.Offset(0, 1).Value = i

Jason

Code not working as expected.
 
Try Mid(C1.Value,9)*1 to convert the text from the Mid formula to a number.

"Ayo" wrote:

I have a snippet of a code shown below, when
c.value=3 and c1.value= "Cluster 3", i is still showing zero. I can't
figut=re out what is going on here. The only thing I noticed is that c.values
are double and c1.values are strings. I don't know if that makes any
difference.
Please help.

For Each c1 In Worksheets(1).Range("A39:A46").Cells
i = 0
For Each c In clusterRange.Cells
If c.Value = Mid(c1.Value, 9) Then
i = i + 1
End If
Next c
c1.Offset(0, 1).Value = i


Ayo

Code not working as expected.
 
Thanks Jason. That seems to do the trick.

"Jason" wrote:

Try Mid(C1.Value,9)*1 to convert the text from the Mid formula to a number.

"Ayo" wrote:

I have a snippet of a code shown below, when
c.value=3 and c1.value= "Cluster 3", i is still showing zero. I can't
figut=re out what is going on here. The only thing I noticed is that c.values
are double and c1.values are strings. I don't know if that makes any
difference.
Please help.

For Each c1 In Worksheets(1).Range("A39:A46").Cells
i = 0
For Each c In clusterRange.Cells
If c.Value = Mid(c1.Value, 9) Then
i = i + 1
End If
Next c
c1.Offset(0, 1).Value = i



All times are GMT +1. The time now is 04:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com