Inputnya mungkin ada spasinya.
coba ubah script menjadi :
Private Sub jth_tempo_Change()
Dim lChar As Long
Dim sText As String
on error goto keluar
sText = CStr(CLng(Replace$(jth_tempo.Text, "-", vbNullString)))
lChar = Len(sText)
Select Case lChar
Case 5, 6
sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2)
If Not IsDate(sText & "-01") And lChar = 6 Then
jth_tempo.Text = Left$(sText, 6)
Else
jth_tempo.Text = sText
End If
Case 7, 8
sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2) & "-" &
Mid$(sText, 7, 2)
If Not IsDate(sText) And lChar = 8 Then
jth_tempo.Text = Left$(sText, 9)
Else
jth_tempo.Text = sText
End If
End Select
keluar:
err.clear
on error goto 0
End Sub
>> Format number :
# mewakili sebuah angka bukan nol
0 mewakili sebuah angka
Jika ingin selalu tampil apa adanya (0 ya ditulis 0) gunakan karakter 0
daripada #
Atur dan pilih akan diletakkan dimana si karakter 0 dan dimana yang #. Atau
malah semua 0 atau semua #
Contoh :
di format 00.00 akan selalu tampil minimal 2 digit didepan koma dan 2 digit
dibelakang koma
Wassalam,
Kid.
2013/2/15 Eko NS <[email protected]>
> **
>
>
> saya sudah coba mr. Kid, tp debug di baris ke-3 (mark with >).
> FYI control textbox bernama jth_tempo, jadi saya modif mjd spt ini
>
> Private Sub jth_tempo_Change()
> Dim lChar As Long
> Dim sText As String
>
> > sText = CStr(CLng(Replace$(jth_tempo.Text, "-", vbNullString)))
> lChar = Len(sText)
> Select Case lChar
> Case 5, 6
> sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2)
> If Not IsDate(sText & "-01") And lChar = 6 Then
> jth_tempo.Text = Left$(sText, 6)
> Else
> jth_tempo.Text = sText
> End If
> Case 7, 8
> sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2) & "-" &
> Mid$(sText, 7, 2)
> If Not IsDate(sText) And lChar = 8 Then
> jth_tempo.Text = Left$(sText, 9)
> Else
> jth_tempo.Text = sText
> End If
> End Select
> End Sub
>
> kira2 apanya yg salah ya?
>
>
> 2013/2/15 Mr. Kid <[email protected]>
>
> **
>>
>>
>> Untuk yang date.
>> Syaratnya, input dalam format YYYYMMDD :: 4 digit tahun diikuti 2 digit
>> bulan dan diakhiri 2 digit tanggal (total input = 8 digit selalu)
>> Dipilih format input ini agar tidak terbentur masalah regional setting
>> komputer yang bisa jadi berbeda antar komputernya.
>>
>> Misal nama control textbox adalah txtTgl
>> Pada event change txtTgl diberi script :
>> Dim lChar As Long
>> Dim sText As String
>>
>> sText = CStr(CLng(Replace$(txtTgl.Text, "-", vbNullString)))
>> lChar = Len(sText)
>> Select Case lChar
>> Case 5, 6
>> sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2)
>> If Not IsDate(sText & "-01") And lChar = 6 Then
>> txtTgl.Text = Left$(sText, 6)
>> Else
>> txtTgl.Text = sText
>> End If
>> Case 7, 8
>> sText = Left$(sText, 4) & "-" & Mid$(sText, 5, 2) & "-" &
>> Mid$(sText, 7, 2)
>> If Not IsDate(sText) And lChar = 8 Then
>> txtTgl.Text = Left$(sText, 9)
>> Else
>> txtTgl.Text = sText
>> End If
>> End Select
>>
>> Wassalam,
>> Kid.
>>
>> 2013/2/15 Eko NS <[email protected]>
>>
>>> **
>>>
>>>
>>> misi para mastah excel,
>>>
>>> ane ada sedikit kesulitan dalam pembuatan makro & ingin bantuan dari
>>> para mastah.
>>>
>>> dalam userform ane ingin ketika input data angka akan secara otomatis
>>> tampil dengan pemisah titik (.) dan untuk tanggal terpisahkan dengan strip
>>> (-) antara tanggal, bulan & tahun.
>>> maksud ane tampilan tersebut langsung dapat terlihat ketika isi
>>> userform, bukan pada tabel hasilnya.
>>>
>>> terima kasih.
>>>
>>>
>>> _
>>>
>>
>>
>
>
> --
> * * Eko Nur Subagyo*
> *
> *
> * Subdit Pinjaman Daerah*
> * Ditjen Perimbangan Keuangan - Kemenkeu*
> * Jl. DR. Wahidin No. 1 Jakarta*
>
>
>