0E560 = 0?
On Feb 6, 9:44 am, "Joergen Bondesen" wrote:
In a cell, I have this information: 0E560
I'm testing cells for Zero's and the above cell contains Zero. Why?
I cannot duplicate your problem. That is, your macro seems to work
exactly as I would expect, going to the Stop statement only for the
cells that contain "000", "00" and "0".
A good way to debug simple macros like this is to add Debug.Print
statements. Use ctrl-G to see the Immediate Window, where the
Debug.Print output goes.
For example, I replaced the Stop statement with the statement:
Debug.Print "ZeroTRIMCount"
(You can also put a breakpoint there by putting the cursor on that
line, then pressing alt-F9.)
And I added the following statements, showing the pre-existing code
line above:
For Each cell In Selection
cnt = cnt + 1
Debug.Print "----- "; cnt
[....]
TestCVdig = Trim(cell.Value)
Debug.Print VarType(cell); Chr(34) & TestCVdig & Chr(34)
[....]
TestCV = Trim(cell.Value)
Debug.Print Chr(34) & TestCV & Chr(34)
[....]
Debug.Print Chr(34) & TestCVReplace & Chr(34)
Debug.Print Len(TestCV); Len(TestCVReplace)
Of course, I also added the declaration:
Dim cnt as long
----- original posting -----
On Feb 6, 9:44*am, "Joergen Bondesen" wrote:
Hi NG
*Testdata
*0E560
*0E310
*000
*00
*0
*1
*I have experienced an odd problem.
*In a cell, I have this information: * 0E560
*I'm testing cells for Zero's and the above cell contains Zero. Why?
*Macro belowe is my way to solve the probleme.
*Is there a more elegant way?
Option Explicit
Sub test()
* * Dim cell As Range
* * For Each cell In Selection
* * * '// Why zero??
* * * Dim TestCVdig As Double
* * * TestCVdig = Trim(cell.Value)
* * * '// Only trim zero: 0
* * * Dim TestCV As String
* * * TestCV = Trim(cell.Value)
* * * Dim TestCVReplace As String
* * * TestCVReplace = Replace(TestCV, "0", "")
* * * If (Len(TestCV) < Len(TestCVReplace) And _
* * * * Len(TestCV) 1 And Len(TestCVReplace) = 0) Or _
* * * * TestCV = "0" Then
* * * * Stop
* * * * '// Function
* * * * 'ZeroTRIMCount cell
* * * End If
* * Next cell
End Sub
--
Best regards
Joergen Bondesen
|