VBA:在细胞中添加

时间:2017-06-27 07:29:41

标签: vba excel-vba excel

我对数据进行排序,并且需要以相同的方式对其进行格式化。输入可能包含单元格 6 + 18
12
3
5个+ 14个
20个
我想让它们全部整数。我到目前为止写过这个:

If InStr(data.Cells(x, 8), "+") > 0 Then
    'Still trying to figure out this part
Else
    calc.Cells((lrcalc + 1), (col + s)).Value = data.Cells(x, 8)
End If

如何在" +"左侧添加值?签到右边的值?

1 个答案:

答案 0 :(得分:5)

好吧,没有必要检查+。只需在每个单元格中添加=符号,然后让Excel计算它;)

Sub Sample()
    Dim lRow As Long, i As Long
    Dim ws As Worksheet

    '~~> Change this to the relevant sheet
    Set ws = ActiveSheet

    With ws
        '~~> Find last row
        lRow = .Range("A" & .Rows.Count).End(xlUp).Row

        For i = 1 To lRow
            With .Range("A" & i)
                .Formula = "=" & .Value
                .Value = .Value
            End With
        Next i
    End With
End Sub

<强>截图

enter image description here