run time error 438 "Object Does not Support this property or method

jamilm

Well-known Member
Joined
Jul 21, 2011
Messages
740
masters,


I have a error in the following code . run time error 438 "Object Does not Support this property or method." yellow debugger stops at Ln 34

can you please tell me what is wrong here?


Code:
Sub SumRowsColumns30Sheet()

Dim LastRow         As Long
Dim iRow            As Long
Dim iCol            As Integer
Dim nSheets        As Integer '/ This is the variable I used to try to calculate across 3 sheets.
                        '/ I removed the variable from the procedure when it didn't work.
For nSheets = 1 To 30
    With Worksheets(nSheets)
    
    LastRow = 0
    
        '/ Find last row
        For iCol = 5 To 18   '/Cols E:R
            'Placed a "." right before Cells
            iRow = .Cells(65536, iCol).End(xlUp).Row
            If iRow > LastRow Then LastRow = iRow
        Next iCol
          
            '/ Place row totals in column R
            For iRow = 2 To LastRow
                'Placed a "." right before Cells
                'Sum until column C only.
                .Cells(iRow, "R") = Application.WorksheetFunction.Sum(Range(.Cells(iRow, "E"), .Cells(iRow, "R")))
            Next iRow
                
            '/ Place column total in new last row
            For iCol = 5 To 18
                'Placed a "." right before Cells
                'Sum starting from row 2
                .Cells(LastRow + 1, iCol) = Application.WorksheetFunction.Sum(Range(.Cells(3, iCol), Cells(.LastRow, iCol)))
            Next iCol
            
    End With
Next nSheets
End Sub
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Remove the "." before LastRow in that line.
 
Upvote 0
Ah - there should also be a "." in front of the last Cells word. (and really, the Range property too)
Code:
.Cells(LastRow + 1, iCol) = Application.WorksheetFunction.Sum(.Range(.Cells(3, iCol), .Cells(LastRow, iCol)))
 
Upvote 0
it is perfect now. thanks very much.


Ah - there should also be a "." in front of the last Cells word. (and really, the Range property too)
Code:
.Cells(LastRow + 1, iCol) = Application.WorksheetFunction.Sum(.Range(.Cells(3, iCol), .Cells(LastRow, iCol)))
 
Upvote 0

Forum statistics

Threads
1,215,464
Messages
6,124,969
Members
449,200
Latest member
Jamil ahmed

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top