promotion image of download ymail app
Promoted

excel vba 程式設計 vb

如何使用vba寫出一段程式。

例如:0x3 ,0x7f ,0x3 ,0x73 ,0x2 ,0xeb

按下第一個button後

會產生

37f

373

2eb而再按下另一個button後

會變成原來的樣字

0x3,0x7f,0x3,0x73,0x2,0xeb

謝謝!

Update:

先感謝豬皮的回答!~感恩!

Update 2:

那再請問一下,按下第一個BUTTON後,所顯示的資料全部都在A1,有沒有辦法把顯示的資料依序分別放在不同的儲存格?

1 Answer

Rating
  • 豬皮
    Lv 5
    9 years ago
    Favorite Answer

    簡單寫了兩個函數,第一個函數(Merge)可以將單行多個16進位值兩兩轉為多行的值,另一個Separate則是還原。

    假設你的資料放在A1儲存格,按第一個按鈕時,呼叫

    Range("A1") = Merge(Range("A1"))

    按第二個按鈕時,呼叫

    Range("A1") = Separate(Range("A1"))

    函數如下:

    Function Merge(strSrc)

    vData = Split(strSrc, ",")

    strOut = ""

    For i = 0 To UBound(vData) - 1 Step 2

    strOut = IIf(strOut = "", "", strOut & vbCr & vbLf)

    strTmp1 = Trim(vData(i))

    strTmp2 = Trim(vData(i + 1))

    strOut = strOut & Mid(strTmp1, 3, Len(strTmp1) - 2)

    strOut = strOut & Mid(strTmp2, 3, Len(strTmp2) - 2)

    Next i

    Merge = strOut

    End Function

    Function Separate(strSrc)

    vData = Split(strSrc, vbCr & vbLf)

    strOut = ""

    For i = 0 To UBound(vData)

    strOut = IIf(strOut <> "", strOut & " ,", "")

    strTmp2 = Right(vData(i), 2)

    strTmp1 = Left(vData(i), Len(vData(i)) - Len(strTmp2))

    strOut = strOut & "0x" & strTmp1

    strOut = strOut & ", 0x" & strTmp2

    Next i

    Separate = strOut

    End Function

    2011-01-10 09:08:53 補充:

    要放到不同儲存格當然也是可以,等等有空把程式碼寄到你的信箱給你參考。

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.