Consulting

Results 1 to 5 of 5

Thread: Solved: Loop in Column P to Convert value

  1. #1
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location

    Solved: Loop in Column P to Convert value

    Dear Master,
    To the point : I need your help on how to loop in column P to convert a value to Character.
    Let say, 1 = H, 2=I, 3=J ? till 0 =Q.
    Please have a loon into the attached file.

    Many thanks in advance.
    Rgds, Harto

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub ProcessData()
    Dim i As Long, j As Long
    Dim LastRow As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
    For i = 5 To LastRow

    .Cells(i, "P").Value = ""
    For j = 1 To Len(.Cells(i, "F").Value)

    If Mid$(.Cells(i, "F").Value, j, 1) = "0" Then

    .Cells(i, "P").Value = .Cells(i, "P").Value & "Q"
    Else

    .Cells(i, "P").Value = .Cells(i, "P").Value & _
    Chr(Mid$(.Cells(i, "F").Value, j, 1) + 71)
    End If
    Next j
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    Hi Bob,

    Remember, we need to take the number and convert it starting the 5th character then leave it the last 5th character (do not convert it, keep in number format). And, try to modified the code but give me a stuck.
    Please help me again.

    Thanks & Rgds, harto
    [VBA] For j = 5 To 10 'Len(.Cells(i, "F").Value)


    If Mid$(.Cells(i, "F").Value, j, 1) = "0" Then

    .Cells(i, "P").Value = .Cells(i, "P").Value & "Q"
    Else

    .Cells(i, "P").Value = .Cells(i, "P").Value & _
    Chr(Mid$(.Cells(i, "F").Value, j, 1) + 71)
    ' leave it the last 5th value and combine it.
    ' so the value in range P5 will be JHIJKL67890
    ' P6 should be IHJKLM78900
    ' please advice[/VBA]

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Sub ProcessData()
    Dim i As Long, j As Long
    Dim LastRow As Long

    With ActiveSheet

    LastRow = .Cells(.Rows.Count, "F").End(xlUp).Row
    For i = 5 To LastRow

    .Cells(i, "P").Value = ""
    For j = 5 To 9

    If Mid$(.Cells(i, "F").Value, j, 1) = "0" Then

    .Cells(i, "P").Value = .Cells(i, "P").Value & "Q"
    Else

    .Cells(i, "P").Value = .Cells(i, "P").Value & _
    Chr(Mid$(.Cells(i, "F").Value, j, 1) + 71)
    End If
    Next j
    .Cells(i, "P").Value = .Cells(i, "P").Value & Mid$(.Cells(i, "F").Value, 10)
    Next i
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    VBAX Tutor
    Joined
    Sep 2007
    Posts
    265
    Location
    Hi Bob,

    Work well. Thank you so much.
    You are great.

    Have a nice day.
    Best, Harto

Posting Permissions

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