H,mn,s macro excel
jeanclaude
-
jeanclaude -
jeanclaude -
Bonjour, j'insiste...
Pourquoi ma macro ne fonctionne pas SVP...
For i = 1 To 9
ch = Cells(i + 2, 2)
ch1 = Left(ch, Len(ch) - 1)
ch2 = Left(ch1, Len(ch1) - 4)
If Len(ch1) < 7 Then
s = Right(ch1, Len(ch1) - 4)
mn = Left(ch1, Len(ch1) - 4)
h = 0
Else:
s = Right(ch1, Len(ch1) - 6)
mn = Right(ch2, Len(ch2) - 2)
h = Left(ch2, Len(ch2) - 3)
End If
Cells(i + 2, 3) = (h & ":" & mn & ":" & s)
Next i
merci...
Pourquoi ma macro ne fonctionne pas SVP...
For i = 1 To 9
ch = Cells(i + 2, 2)
ch1 = Left(ch, Len(ch) - 1)
ch2 = Left(ch1, Len(ch1) - 4)
If Len(ch1) < 7 Then
s = Right(ch1, Len(ch1) - 4)
mn = Left(ch1, Len(ch1) - 4)
h = 0
Else:
s = Right(ch1, Len(ch1) - 6)
mn = Right(ch2, Len(ch2) - 2)
h = Left(ch2, Len(ch2) - 3)
End If
Cells(i + 2, 3) = (h & ":" & mn & ":" & s)
Next i
merci...
Configuration: Windows XP Internet Explorer 6.0
2 réponses
-
Bonjour,
ben comme ça sans connaîte ce qu'il y a en b2 à b11
on peut supposer que c'est un temps au format texte....
Cette information est la première chose que tu mets dans ta moulinette.... mais moi je ne la trouve pas...
puisqu'il s'agit de transformer heure en texte et aussi faire l'inverse....
je te conseil de regarder les fonctions
CSTR
MyString = CStr(MyDouble) ' MyString contient "437,324".
et
CDADE
MyTime = "4:35:47 PM" ' Définit l'heure.
MyShortTime = CDate(MyTime) ' Convertit en type Date. -
Bonjour jeanclaude et Bidouilleu_R,
Compte tenu de la précédente discusssion de jeanclaude qui est restée semble-t-il non résolue, je propose de modifier le code avec pour principe de "scanner" la chaine afin de bien dégager les heures, minutes et secondes. Voila le code qui semble bien fonctionner :
For I = 1 To 9 ch = Cells(I + 2, 2) h = "00" nbcar = Len(ch) For car = 1 To nbcar If Mid(ch, car, 1) = "h" Or Mid(ch, car, 1) = "H" Then h = Left(ch, car - 1) ch = Right(ch, nbcar - car) End If Next car mn = "00" nbcar = Len(ch) For car = 1 To nbcar If Mid(ch, car, 1) = "m" Then mn = Left(ch, car - 1) ch = Right(ch, nbcar - car - 1) End If If Mid(ch, car, 1) = "'" Then mn = Left(ch, car - 1) ch = Right(ch, nbcar - car) End If Next car nbcar = Len(ch) s = Left(ch, nbcar - 1) Cells(I + 2, 3) = (h & ":" & mn & ":" & s) Next I
A+-
-
Salut à toi,
C'est parfait, ça marche et j'ai ainsi découvert un fonction.
Toutefois,je ne comprends pas le pourquoi de
If Mid(ch, car, 1) = "'" Then
mn = Left(ch, car - 1)
ch = Right(ch, nbcar - car)
End If
Autre question, je cherche à repasser de, par exemple 02:21:34, à 2h21mn34s.J'ai esayé qqchose de semblable, mais je me heurte sans doute à la différence entre nombre et chaîne, et ne m'en sors pas...
Merci.
-