0E560 = 0?

  • Thread starter Joergen Bondesen
  • Start date
J

Joergen Bondesen

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
 
J

joeu2004

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 -----
 
D

Dave Peterson

0E560 looks like a number written in scientific notation to VBA--which is very
forgiving.

0*(10^560) = 0

Excel's =isnumber() is much more strict.

Maybe you could use that in your test:

if application.isnumber(cell.value) then
'it's a number...

The value in the cell is really text, right?
 
J

joeu2004

Errata....

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".

But you knew that. You wrote: "Macro belowe is my way to solve the
probleme". Fortunately, Dave understood your problem better and
provided a good answer.
 
J

Joergen Bondesen

Hi joeu2004

Thanks for your answer.

Sorry, please forgive me for my bad English and explanation.
--

Best regards
Jorgen Bondesen


"joeu2004" <[email protected]> skrev i en meddelelse
Errata....

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".

But you knew that. You wrote: "Macro belowe is my way to solve the
probleme". Fortunately, Dave understood your problem better and
provided a good answer.
 
J

Joergen Bondesen

Hi Dave

Thanks for your answer and inspiration.
0*(10^560) = 0
Yes. Please look in macro below.

This is my data
0 zero
'000 starting with apostrophe
000 cell is txt formated
0E560

Option Explicit

Sub test02()
Dim cell As Range
For Each cell In Selection

Dim InStrE As Long
InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then
MsgBox cell.Value
'// Function
'ZeroTRIMCount cell
End If
Next cell
End Sub
 
D

Dave Peterson

I don't understand the question.

And you didn't say what was in the cell that displayed 0E560. Was that a number
formatted like this? Or was it text?

And what would you expect returned from those 4 cells?

And what was returned from those 4 cells?
 
J

joeu2004

Please look in macro below.

Is this the macro that caused you problems in the first place? Or is
this yet another attempt to work around the problem?

It would be helpful if you posted the original macro that caused the
problem. You can also share your work-arounds. But I presume you
would prefer the best fix for your original macro.
 
J

Joergen Bondesen

--

Med venlig hilsen
Jørgen Bondesen


Dave Peterson said:
I don't understand the question.

And you didn't say what was in the cell that displayed 0E560. Was that a
number
formatted like this? Or was it text?

And what would you expect returned from those 4 cells?

And what was returned from those 4 cells?
 
J

Joergen Bondesen

Hi Dave.

Sorry about the 2 empty answers.

I do hope this explanation is satisfactory.

Each day my colleagues and I receive Excel files.



I have made a macro to control these files.



I control each cell for containing only . (dot); , (comma); ;
(semicolon); -(minus) and 0 (Zero)

All these things give problem in the further production.



This is my data in cells (we now only concentrate about 0 Zero)
Cell1: 0 zero; [macro will count cell as 0 Zero = ok]
Cell2: '000 starting with apostrophe, [macro will count cell as 0 Zero =
ok]
Cell3: 000 Cell is txt formatted; [macro will count cell as 0 Zero =
ok]



This part test for 0 (Zero)

Sub Test01()

Dim cell As Range

For Each cell In Selection

'// only trim zero: 0

If Trim(cell.Value) = 0 Then

'// Only for illustrate

MsgBox Trim(cell.Value)

'// Function (Count Quantity and gives me cell reference.)

'ZeroTRIMCount cell

End If

Next cell

End Sub



Everything is OK, until my macro finds a cell containing (Cell4:) 0E560
as 0 Zero (Cell format is scientific)

I expect my macro to read: 0E560 and therefore not count the cell as 0
Zero.



This is a huge problem, because our customer will be very angry if this
information is missing in the further production.



To solve my problem, I change my macro to after inspiration from you:


Sub test02()

Dim cell As Range

For Each cell In Selection



Dim InStrE As Long

InStrE = InStr(1, UCase(cell.Value), "E")



If Trim(cell.Value) = 0 And InStrE = 0 Then

'// Only for illustrate

MsgBox cell.Value

'// Function

'ZeroTRIMCount cell

End If

Next cell

End Sub



I'm using Excel 2007 in a Danish version, but I have tested in a UK version,
with the same result.

You can make a Excelfile with all 4 cells and run Test01 and afterwards
Test02.


--

Best Regards
Joergen Bondesen

 
J

Joergen Bondesen

Hi joeu2004

Look at my reply to Dave now, please.

--

Best regards
Joergen Bondesen


"joeu2004" <[email protected]> skrev i en meddelelse
Please look in macro below.

Is this the macro that caused you problems in the first place? Or is
this yet another attempt to work around the problem?

It would be helpful if you posted the original macro that caused the
problem. You can also share your work-arounds. But I presume you
would prefer the best fix for your original macro.
 
D

Dave Peterson

Try using application.isnumber(cell.value) to test to see if the value is
numeric.

if application.isnumber(cell.value) then
if cell.value = 0 then
'increment your count
end if
end if

VBA will try to treat things that look like numbers as numbers.

ps. if you look at the format for that cell with 0E560 in it, you may see
Scientific. But if you use:

=isnumber(a4)
You'll see that it's false.




Joergen said:
Hi Dave.

Sorry about the 2 empty answers.

I do hope this explanation is satisfactory.

Each day my colleagues and I receive Excel files.

I have made a macro to control these files.

I control each cell for containing only . (dot); , (comma); ;
(semicolon); -(minus) and 0 (Zero)

All these things give problem in the further production.

This is my data in cells (we now only concentrate about 0 Zero)
Cell1: 0 zero; [macro will count cell as 0 Zero = ok]
Cell2: '000 starting with apostrophe, [macro will count cell as 0 Zero =
ok]
Cell3: 000 Cell is txt formatted; [macro will count cell as 0 Zero =
ok]

This part test for 0 (Zero)

Sub Test01()

Dim cell As Range

For Each cell In Selection

'// only trim zero: 0

If Trim(cell.Value) = 0 Then

'// Only for illustrate

MsgBox Trim(cell.Value)

'// Function (Count Quantity and gives me cell reference.)

'ZeroTRIMCount cell

End If

Next cell

End Sub

Everything is OK, until my macro finds a cell containing (Cell4:) 0E560
as 0 Zero (Cell format is scientific)

I expect my macro to read: 0E560 and therefore not count the cell as 0
Zero.

This is a huge problem, because our customer will be very angry if this
information is missing in the further production.

To solve my problem, I change my macro to after inspiration from you:

Sub test02()

Dim cell As Range

For Each cell In Selection

Dim InStrE As Long

InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then

'// Only for illustrate

MsgBox cell.Value

'// Function

'ZeroTRIMCount cell

End If

Next cell

End Sub

I'm using Excel 2007 in a Danish version, but I have tested in a UK version,
with the same result.

You can make a Excelfile with all 4 cells and run Test01 and afterwards
Test02.

--

Best Regards
Joergen Bondesen
 
D

Dave Peterson

I didn't notice that you wanted to count the text '0 and '000 as zeros.

This is more complete:

Option Explicit
Sub Test01()

Dim cell As Range
Dim lCtr As Long
Dim FoundNonDigit As Boolean
Dim ZeroCtr As Long

ZeroCtr = 0
For Each cell In Selection
If Application.IsNumber(cell.Value) Then
If cell.Value = 0 Then
ZeroCtr = ZeroCtr + 1
End If
Else
If IsNumeric(cell.Text) Then
'check for just digits
For lCtr = 1 To Len(cell.Text)
If IsNumeric(Mid(cell.Text, lCtr, 1)) Then
'ok, keep looking
Else
'not a digit, get out
FoundNonDigit = True
Exit For
End If
Next lCtr
End If
If FoundNonDigit = True Then
'don't add it
Else
If CDbl(cell.Value) = 0 Then
ZeroCtr = ZeroCtr + 1
End If
End If
End If
Next cell

MsgBox ZeroCtr

End Sub


Joergen said:
Hi Dave.

Sorry about the 2 empty answers.

I do hope this explanation is satisfactory.

Each day my colleagues and I receive Excel files.

I have made a macro to control these files.

I control each cell for containing only . (dot); , (comma); ;
(semicolon); -(minus) and 0 (Zero)

All these things give problem in the further production.

This is my data in cells (we now only concentrate about 0 Zero)
Cell1: 0 zero; [macro will count cell as 0 Zero = ok]
Cell2: '000 starting with apostrophe, [macro will count cell as 0 Zero =
ok]
Cell3: 000 Cell is txt formatted; [macro will count cell as 0 Zero =
ok]

This part test for 0 (Zero)

Sub Test01()

Dim cell As Range

For Each cell In Selection

'// only trim zero: 0

If Trim(cell.Value) = 0 Then

'// Only for illustrate

MsgBox Trim(cell.Value)

'// Function (Count Quantity and gives me cell reference.)

'ZeroTRIMCount cell

End If

Next cell

End Sub

Everything is OK, until my macro finds a cell containing (Cell4:) 0E560
as 0 Zero (Cell format is scientific)

I expect my macro to read: 0E560 and therefore not count the cell as 0
Zero.

This is a huge problem, because our customer will be very angry if this
information is missing in the further production.

To solve my problem, I change my macro to after inspiration from you:

Sub test02()

Dim cell As Range

For Each cell In Selection

Dim InStrE As Long

InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then

'// Only for illustrate

MsgBox cell.Value

'// Function

'ZeroTRIMCount cell

End If

Next cell

End Sub

I'm using Excel 2007 in a Danish version, but I have tested in a UK version,
with the same result.

You can make a Excelfile with all 4 cells and run Test01 and afterwards
Test02.

--

Best Regards
Joergen Bondesen
 
J

joeu2004

For Each cell In Selection
    If Trim(cell.Value) = 0 Then
      MsgBox Trim(cell.Value)
  End If
Next cell

One way:

For Each cell In Selection
If (Application.IsNumber(cell) And cell = 0) Or _
(Not Application.IsNumber(cell) And _
Trim(cell) <> "" And Trim(Replace(cell, "0", "")) = "")
Then
' ZeroTRIMCount cell
Debug.Print "OKAY ";
Else
Debug.Print "skip ";
End If
Debug.Print cell.Address; " "; TypeName(cell.Value); " "; _
Chr(34) & cell & Chr(34)
Next cell

I tried this with the following examples (and results):

skip $A$1 Empty ""
skip $A$2 String ""
skip $A$3 String " "
OKAY $A$4 Double "0"
OKAY $A$5 String "0"
OKAY $A$6 String "000"
skip $A$7 String "0E540"
OKAY $A$8 Double "0"
skip $A$9 String "0E300"

Note: A8 was entered as 0E+300, a real scientific notation number.
But of course, Excel changed that to a simple zero. With Scientific
formatting, it display as 0.00E+00.
 
J

Joergen Bondesen

Hi Dave.

Thanks for your macro, I like it.
But I have a question.
You are using cell.value (as displayed in formula bar, yes?) and cell.text
(as displayed in cell, yes?).

I can not figure out why you are using cell.text below. Is it possible for
you to explain it for me?

If IsNumeric(cell.Text) Then
'check for just digits
For lCtr = 1 To Len(cell.Text)
If IsNumeric(Mid(cell.Text, lCtr, 1)) Then
'ok, keep looking
Else
'not a digit, get out
FoundNonDigit = True
Exit For
End If
Next lCtr
End If


--

Best Regards
Joergen Bondesen


Dave Peterson said:
I didn't notice that you wanted to count the text '0 and '000 as zeros.

This is more complete:

Option Explicit
Sub Test01()

Dim cell As Range
Dim lCtr As Long
Dim FoundNonDigit As Boolean
Dim ZeroCtr As Long

ZeroCtr = 0
For Each cell In Selection
If Application.IsNumber(cell.Value) Then
If cell.Value = 0 Then
ZeroCtr = ZeroCtr + 1
End If
Else
If IsNumeric(cell.Text) Then
'check for just digits
For lCtr = 1 To Len(cell.Text)
If IsNumeric(Mid(cell.Text, lCtr, 1)) Then
'ok, keep looking
Else
'not a digit, get out
FoundNonDigit = True
Exit For
End If
Next lCtr
End If
If FoundNonDigit = True Then
'don't add it
Else
If CDbl(cell.Value) = 0 Then
ZeroCtr = ZeroCtr + 1
End If
End If
End If
Next cell

MsgBox ZeroCtr

End Sub


Joergen said:
Hi Dave.

Sorry about the 2 empty answers.

I do hope this explanation is satisfactory.

Each day my colleagues and I receive Excel files.

I have made a macro to control these files.

I control each cell for containing only . (dot); , (comma); ;
(semicolon); -(minus) and 0 (Zero)

All these things give problem in the further production.

This is my data in cells (we now only concentrate about 0 Zero)
Cell1: 0 zero; [macro will count cell as 0 Zero = ok]
Cell2: '000 starting with apostrophe, [macro will count cell as 0 Zero
=
ok]
Cell3: 000 Cell is txt formatted; [macro will count cell as 0 Zero =
ok]

This part test for 0 (Zero)

Sub Test01()

Dim cell As Range

For Each cell In Selection

'// only trim zero: 0

If Trim(cell.Value) = 0 Then

'// Only for illustrate

MsgBox Trim(cell.Value)

'// Function (Count Quantity and gives me cell reference.)

'ZeroTRIMCount cell

End If

Next cell

End Sub

Everything is OK, until my macro finds a cell containing (Cell4:)
0E560
as 0 Zero (Cell format is scientific)

I expect my macro to read: 0E560 and therefore not count the cell as 0
Zero.

This is a huge problem, because our customer will be very angry if this
information is missing in the further production.

To solve my problem, I change my macro to after inspiration from you:

Sub test02()

Dim cell As Range

For Each cell In Selection

Dim InStrE As Long

InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then

'// Only for illustrate

MsgBox cell.Value

'// Function

'ZeroTRIMCount cell

End If

Next cell

End Sub

I'm using Excel 2007 in a Danish version, but I have tested in a UK
version,
with the same result.

You can make a Excelfile with all 4 cells and run Test01 and afterwards
Test02.

--

Best Regards
Joergen Bondesen
"Dave Peterson" <[email protected]> skrev i en meddelelse
I don't understand the question.

And you didn't say what was in the cell that displayed 0E560. Was
that
a number
formatted like this? Or was it text?

And what would you expect returned from those 4 cells?

And what was returned from those 4 cells?

Joergen Bondesen wrote:

Hi Dave

Thanks for your answer and inspiration.

0*(10^560) = 0
Yes. Please look in macro below.

This is my data
0 zero
'000 starting with apostrophe
000 cell is txt formated
0E560

Option Explicit

Sub test02()
Dim cell As Range
For Each cell In Selection

Dim InStrE As Long
InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then
MsgBox cell.Value
'// Function
'ZeroTRIMCount cell
End If
Next cell
End Sub
--

Best regards
Joergen Bondesen

"Dave Peterson" <[email protected]> skrev i en meddelelse
0E560 looks like a number written in scientific notation to
VBA--which is
very
forgiving.

0*(10^560) = 0

Excel's =isnumber() is much more strict.

Maybe you could use that in your test:

if application.isnumber(cell.value) then
'it's a number...

The value in the cell is really text, right?

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
 
J

Joergen Bondesen

Hi joeu2004.

Thanks for your macro, I like it.

Additionally I am happy for your debugging, where I now can see
possibilities.

--

Best regards
Joergen Bondesen


"joeu2004" <[email protected]> skrev i en meddelelse
For Each cell In Selection
If Trim(cell.Value) = 0 Then
MsgBox Trim(cell.Value)
End If
Next cell

One way:

For Each cell In Selection
If (Application.IsNumber(cell) And cell = 0) Or _
(Not Application.IsNumber(cell) And _
Trim(cell) <> "" And Trim(Replace(cell, "0", "")) = "")
Then
' ZeroTRIMCount cell
Debug.Print "OKAY ";
Else
Debug.Print "skip ";
End If
Debug.Print cell.Address; " "; TypeName(cell.Value); " "; _
Chr(34) & cell & Chr(34)
Next cell

I tried this with the following examples (and results):

skip $A$1 Empty ""
skip $A$2 String ""
skip $A$3 String " "
OKAY $A$4 Double "0"
OKAY $A$5 String "0"
OKAY $A$6 String "000"
skip $A$7 String "0E540"
OKAY $A$8 Double "0"
skip $A$9 String "0E300"

Note: A8 was entered as 0E+300, a real scientific notation number.
But of course, Excel changed that to a simple zero. With Scientific
formatting, it display as 0.00E+00.
 
D

Dave Peterson

The .value of 0E560 will be 0. So using .value won't help me distinguish
between a real 0 and the text 0E560.





Joergen said:
Hi Dave.

Thanks for your macro, I like it.
But I have a question.
You are using cell.value (as displayed in formula bar, yes?) and cell.text
(as displayed in cell, yes?).

I can not figure out why you are using cell.text below. Is it possible for
you to explain it for me?

If IsNumeric(cell.Text) Then
'check for just digits
For lCtr = 1 To Len(cell.Text)
If IsNumeric(Mid(cell.Text, lCtr, 1)) Then
'ok, keep looking
Else
'not a digit, get out
FoundNonDigit = True
Exit For
End If
Next lCtr
End If

--

Best Regards
Joergen Bondesen

Dave Peterson said:
I didn't notice that you wanted to count the text '0 and '000 as zeros.

This is more complete:

Option Explicit
Sub Test01()

Dim cell As Range
Dim lCtr As Long
Dim FoundNonDigit As Boolean
Dim ZeroCtr As Long

ZeroCtr = 0
For Each cell In Selection
If Application.IsNumber(cell.Value) Then
If cell.Value = 0 Then
ZeroCtr = ZeroCtr + 1
End If
Else
If IsNumeric(cell.Text) Then
'check for just digits
For lCtr = 1 To Len(cell.Text)
If IsNumeric(Mid(cell.Text, lCtr, 1)) Then
'ok, keep looking
Else
'not a digit, get out
FoundNonDigit = True
Exit For
End If
Next lCtr
End If
If FoundNonDigit = True Then
'don't add it
Else
If CDbl(cell.Value) = 0 Then
ZeroCtr = ZeroCtr + 1
End If
End If
End If
Next cell

MsgBox ZeroCtr

End Sub


Joergen said:
Hi Dave.

Sorry about the 2 empty answers.

I do hope this explanation is satisfactory.

Each day my colleagues and I receive Excel files.

I have made a macro to control these files.

I control each cell for containing only . (dot); , (comma); ;
(semicolon); -(minus) and 0 (Zero)

All these things give problem in the further production.

This is my data in cells (we now only concentrate about 0 Zero)
Cell1: 0 zero; [macro will count cell as 0 Zero = ok]
Cell2: '000 starting with apostrophe, [macro will count cell as 0 Zero
=
ok]
Cell3: 000 Cell is txt formatted; [macro will count cell as 0 Zero =
ok]

This part test for 0 (Zero)

Sub Test01()

Dim cell As Range

For Each cell In Selection

'// only trim zero: 0

If Trim(cell.Value) = 0 Then

'// Only for illustrate

MsgBox Trim(cell.Value)

'// Function (Count Quantity and gives me cell reference.)

'ZeroTRIMCount cell

End If

Next cell

End Sub

Everything is OK, until my macro finds a cell containing (Cell4:)
0E560
as 0 Zero (Cell format is scientific)

I expect my macro to read: 0E560 and therefore not count the cell as 0
Zero.

This is a huge problem, because our customer will be very angry if this
information is missing in the further production.

To solve my problem, I change my macro to after inspiration from you:

Sub test02()

Dim cell As Range

For Each cell In Selection

Dim InStrE As Long

InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then

'// Only for illustrate

MsgBox cell.Value

'// Function

'ZeroTRIMCount cell

End If

Next cell

End Sub

I'm using Excel 2007 in a Danish version, but I have tested in a UK
version,
with the same result.

You can make a Excelfile with all 4 cells and run Test01 and afterwards
Test02.

--

Best Regards
Joergen Bondesen

"Dave Peterson" <[email protected]> skrev i en meddelelse
I don't understand the question.

And you didn't say what was in the cell that displayed 0E560. Was
that
a number
formatted like this? Or was it text?

And what would you expect returned from those 4 cells?

And what was returned from those 4 cells?

Joergen Bondesen wrote:

Hi Dave

Thanks for your answer and inspiration.

0*(10^560) = 0
Yes. Please look in macro below.

This is my data
0 zero
'000 starting with apostrophe
000 cell is txt formated
0E560

Option Explicit

Sub test02()
Dim cell As Range
For Each cell In Selection

Dim InStrE As Long
InStrE = InStr(1, UCase(cell.Value), "E")

If Trim(cell.Value) = 0 And InStrE = 0 Then
MsgBox cell.Value
'// Function
'ZeroTRIMCount cell
End If
Next cell
End Sub
--

Best regards
Joergen Bondesen

"Dave Peterson" <[email protected]> skrev i en meddelelse
0E560 looks like a number written in scientific notation to
VBA--which is
very
forgiving.

0*(10^560) = 0

Excel's =isnumber() is much more strict.

Maybe you could use that in your test:

if application.isnumber(cell.value) then
'it's a number...

The value in the cell is really text, right?

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
 
J

Joergen Bondesen

Hi Dave



Obvious. :cool:

Thanks for taking you time to help me.





Best Regards

Joergen Bondesen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top