I have the following code which I found to sum the data fromt he current range of cells. I tried asking at tht site, but the thread seems to be long since forgotten. When I run it I get as error saying "Method 'Range' of object '_Gloabal' failes"...I am very new to VBA, so I am really struggling to figure out exactly what this code is doing, or why it isn't working, so I was hoping someone here could figure outn what is wrong with it.
Sub AddingAtTheRear()
Dim c As Range, R As Range, MyStr2 As String
Dim MyStr As String, x As Integer
Set c = ActiveSheet.UsedRange
MyStr = c.SpecialCells(xlCellTypeConstants, 23).Address
MyStr2 = c.SpecialCells(xlCellTypeFormulas, 23).Address
Set R = Range(MyStr & "," & MyStr2)
For x = 4 To R.Columns.Count
MyStr2 = Cells(65536, R.Columns(x).Column).End(xlUp).Address
MyStr = Range(R.Columns(x).Address & ":" & MyStr2).Address
Set c = Range(MyStr)
Range(MyStr2).Offset(2, 0).Formula = "=sum(" & c.Address & ")"
Next
End Sub
When the error appears, it highlights the line with
Set R=Range(...)
Hopefully this makes sense, and someone can help me out.
Thanks,
Chris
Sub AddingAtTheRear()
Dim c As Range, R As Range, MyStr2 As String
Dim MyStr As String, x As Integer
Set c = ActiveSheet.UsedRange
MyStr = c.SpecialCells(xlCellTypeConstants, 23).Address
MyStr2 = c.SpecialCells(xlCellTypeFormulas, 23).Address
Set R = Range(MyStr & "," & MyStr2)
For x = 4 To R.Columns.Count
MyStr2 = Cells(65536, R.Columns(x).Column).End(xlUp).Address
MyStr = Range(R.Columns(x).Address & ":" & MyStr2).Address
Set c = Range(MyStr)
Range(MyStr2).Offset(2, 0).Formula = "=sum(" & c.Address & ")"
Next
End Sub
When the error appears, it highlights the line with
Set R=Range(...)
Hopefully this makes sense, and someone can help me out.
Thanks,
Chris