Tuesday, April 5, 2016

My stupid version of autosum macro

Sub add()

Dim c As Range
Dim i As Integer
Dim colname As String
Dim col2 As String
Dim col3 As String
col3 = ""
Dim ws As Worksheet

Set ws = ActiveSheet
Dim colnum As Integer
i = 0
Dim result As Integer

    For Each c In Selection
    colname = ActiveCell.Address
    'MsgBox (colname)
       i = i + c.Value
Next c
result = i

col2 = Replace(colname, "$", "")
 For i = 1 To Len(col2)
        If Not IsNumeric(Mid(col2, i, 1)) Then
            col3 = col3 & Mid(col2, i, 1)
        End If
    Next i

MsgBox (col3)

colnum = (Range(col3 & 1).Column)
  For Each cell In ws.Columns(colnum).Cells
  If IsEmpty(cell) = True Then cell.Select: Exit For
Next cell
  ActiveCell.Value = "hello the result is " & result

End Sub

No comments:

Post a Comment