VBA - If number is decimal then...
Solved
zivodul8
Posted messages
248
Status
Member
-
blux Posted messages 5051 Registration date Status Moderator Last intervention -
blux Posted messages 5051 Registration date Status Moderator Last intervention -
Bonjour,
My problem is simple: I am looking for a piece of VBA code that determines whether a number is a decimal or not. For example:
Thank you!
My problem is simple: I am looking for a piece of VBA code that determines whether a number is a decimal or not. For example:
If n = 3.22 then align right Else ( n = 3) align left End if
Thank you!
7 answers
-
Hello,
What I advise you to do is
IF your string contains a special character here a point THEN
align to the right
ELSE
align to the left
END If
In fact, whenever you encounter the element point in your string, you can deduce that it is a decimal number. -
I couldn't manage to do a:
Application.WorksheetFunction.Search
Are there any other methods? -
Hello,
you can do this with the int(number) function which returns the integer part of a number.
If it is equal to the number itself, it means there is no decimal.
IF INT(number) = number THEN ... END IF
--
A+ Blux"Fools dare to do anything. That's how we recognize them."
-
-
Voici la traduction de votre message : I have another (quick) problem. I am trying to determine the line number where, in a column, two empty cells are consecutively vertical. Here's what I've done but it doesn't work:
Sub NbLigne() Dim NbLigne, i As Integer i = 1 Do While Range("A" & i).Value <> "" And Range("A" & i + 1).Value <> "" NbLigne = i i = i + 1 Loop MsgBox NbLigne End Sub
Thank you! -
I have solved it; I just found out that in VBA, AND is translated as
or
and notand
!-
-
It's not in VBA, it's in Boolean logic, but only because you have <>, if you had =, you would need to put an AND.
The explanations here:
https://forums.commentcamarche.net/forum/affich-16025052-shell-condition
And as I said, it's an old thing, as old as computers ;-) -
-
-
What you can do is:
Dim nombre1 as integer Dim nombre2 as string Nombre1=Int(nombre2) If nombre2%nombre1 = 0 then shift left Else shift right end if