Help with "Runtime error 1004 Application-defined or object defined error" !!!

Orongo

Board Regular
Joined
Nov 6, 2011
Messages
83
Hi

I have had my head spinning with this error. Its the first time I get it and I can't get around it and my deadline is closing in fast. The code is quite straight forward (or what do you say?). I'm trying to make the macro to write out a matrix of number with each element in one cell. The error occurs for a 72x2 matrix. Please help me. I don't want to spend more of my evenings with this error ='(


Function Write2Sheet(toPrint As Variant, position As Variant, sheet As String)
Dim sRow As Integer, sColumn As Integer

sColumn = position(1)

Worksheets(sheet).Range(Cells(sRow, sColumn), _
Cells(sRow + UBound(toPrint, 1), sColumn + UBound(toPrint, 2))).Value = toPrint

End Function
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
You aren't calling this function from the worksheet, are you?
 
Upvote 0
Maybe ...
Code:
Sub Write2Sheet(toPrint As Variant, position As Variant, sSht As String)
    Dim iRow As Long
    Dim iCol As Long
 
    iCol = position(1)
    Worksheets(sSht).Cells(iRow, iCol).Resize(UBound(toPrint, 1), UBound(toPrint, 2)).Value = toPrint
End Sub
 
Upvote 0
sRow in the function (or iRow in the sub) doesn't seem to be initialized.
 
Upvote 0
Nice catch, I completely missed that.

I was looking at the fact that the two Cells references were not qualified.
 
Upvote 0

Forum statistics

Threads
1,222,405
Messages
6,165,867
Members
451,989
Latest member
DannyBoy1977

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