Consulting

Results 1 to 3 of 3

Thread: Solved: WorksheetFunction.Rept or "0"?

  1. #1
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location

    Solved: WorksheetFunction.Rept or "0"?

    Hi there,

    I am trying write some data to txt from xls file.

    But there is a problem.

    The result of the current codes:
    <TICKER>,<PER>,<DATE>,<TIME>,<HIGH>,<LOW>,<CLOSE>,<VOLUME>
    ABANA.E,60,19940714,11248,0.032,0.029,0.030,24827
    ABANA.E,60,19950714,12345,0.033,0.030,0.032,45496
    ABANA.E,60,19960714,134556,0.034,0.030,0.032,7535
    ABANA.E,60,19970714,45557,0.033,0.030,0.032,14289

    My wish:

    <TICKER>,<PER>,<DATE>,<TIME>,<HIGH>,<LOW>,<CLOSE>,<VOLUME>
    ABANA.E,60,19940714,112408,0.032,0.029,0.030,24827
    ABANA.E,60,19950714,120345,0.033,0.030,0.032,45496
    ABANA.E,60,19960714,134556,0.034,0.030,0.032,7535
    ABANA.E,60,19970714,045557,0.033,0.030,0.032,14289

    In Column D, if Hour or Minute or Second's lenght 2 so it is ok. But i want to write 2 character even if lenght is 1.

    I tried WorksheetFunction.Rept but i couldn't solve it.

    Any ideas or help me please?

    I attached the file.

    Thanks in advance.
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Location
    Nanaimo, British Columbia, Cananda
    Posts
    568
    Location
    Hi,

    Try formatting the cells containing the times as Custom using HHMMSS as the format.

    Cheers,

    dr

  3. #3
    VBAX Tutor Erdin? E. Ka's Avatar
    Joined
    Sep 2006
    Location
    Bursa
    Posts
    264
    Location
    Hi rbrhodes,

    I solved the problem now via If-End-If:

    [VBA]
    If Len(Hour(Cells(i, 4))) = 1 Then
    H = "0" & Hour(Cells(i, 4))
    Else
    H = Hour(Cells(i, 4))
    End If
    If Len(Minute(Cells(i, 4))) = 1 Then
    M = "0" & Minute(Cells(i, 4))
    Else
    M = Minute(Cells(i, 4))
    End If

    If Len(Second(Cells(i, 4))) = 1 Then
    S = "0" & Second(Cells(i, 4))
    Else
    S = Second(Cells(i, 4))
    End If
    [/VBA]

    Thanks you very much.
    Erdin? E. Kara?am | Loves from Bursa city in Republic of T?rkiye

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •