VBA: Add to Cells

I sort the data and need to be formatted the same way. The input may contain cells with 6 + 18
12
3
5 + 14
20
And I want to make them whole. I have written this so far:

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

How to add the value to the left of the “+” sign to the value to the right?

+4
source share
1 answer

Well there is no need to check +. Just add a character =to each cell and let excel calculate it;)

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

Screenshot

enter image description here

+5
source

Source: https://habr.com/ru/post/1680176/


All Articles