VBA将文本列转换为ASCII值

时间:2018-05-21 16:54:41

标签: excel-vba vba excel

我试图将一列文本转换为ASCII。这个问题类似于链接的问题,但是对于完整字符串而不是单个字符。我使用下面的代码。我没有收到任何错误消息,只是没有变化。请假设我没有VBA编码经验。

Sub Convert_ASCII()
'

Dim last As Long
Dim i As Integer
Dim l As Long
Dim s As String

last = ActiveSheet.Cells(2, "A").End(xlDown).Row

    For i = 2 To last
    s = Cells(i, 1)
        For l = 1 To Len(s)
        Mid(s, l, 1) = Asc(Mid(s, l, 1))
      Next l
   Next i
End Sub

Loop to Convert Characters to ASCII

1 个答案:

答案 0 :(得分:1)

问题在于您正在转换整个字符串,但您永远不会将转换后的字符串分配给单元格。

Sub Convert_ASCII()
    '
    Dim last As Long
    Dim i As Integer
    Dim l As Long
    Dim s As String
    Dim cs As String

    last = ActiveSheet.Cells(2, "A").End(xlDown).Row

    For i = 2 To last
        s = Cells(i, 1)
        cs = ""
        For l = 1 To Len(s)
            cs = cs & Asc(Mid(s, l, 1))
        Next l
        Cells(i, 1) = cs
    Next i
End Sub