将数字转换为文本格式的数字

时间:2015-09-03 16:34:37

标签: excel vba excel-vba excel-formula

如何将列中单元格中的所有数字值转换为文本格式编号?

我试过=TEXT(A2,"A2"),但它对我没有帮助。

2 个答案:

答案 0 :(得分:0)

这是VBA,因为那是你的标签。

循环更改所需列的行。

    Dim ws1 As Excel.Worksheet
    Dim strValue As String

    Set ws1 = ActiveWorkbook.Sheets("Sheet3")

    Dim lRow As Long
    lRow = 1

    ws1.Activate
    'Loop through and record what is in the columns
    Do While lRow <= ws1.UsedRange.Rows.count

        'Make sure we have a value to read into our string
        If ws1.Range("F" & lRow).Value <> "" Then
            'Get the number as a string
            strValue = str(Trim(ws1.Range("F" & lRow).Value))
            'Format the cell as text
            ws1.Range("F" & lRow).NumberFormat = "@"
            'Write the string value back to the cell
            ws1.Range("F" & lRow).Value = strValue
        End If
        lRow = lRow + 1
    Loop

答案 1 :(得分:0)

不使用VBA:选择列,文本到列,分隔符,制表符,列数据格式文本。