PDA

View Full Version : Run time error 438



Leandre1999
09-28-2020, 08:08 AM
Hi,

I'm new to vba and I have an issue when I want to print a matrice in excel trought vba. Run Time Error 438 pops up

Here it is:
https://i.gyazo.com/11e1e8e669fe44ad534980d220e07800.png

When I don't specify that i want it on Sheet1 of my excel I have no problem printing it, but I need to specify it because I got many sheets to work with.

Thank you:)

Bob Phillips
09-28-2020, 08:28 AM
When referencing a codename, you don't specify ThisWorkbook, it can only work in this workbook.

But … you shouldn't write each one to the worksheet as you go, do it in one fell swoop at the end


Sub Question3()
Dim h(1 To 100, 1 To 100) As Long
Dim i As Long
Dim j As Long

For i = 1 To 20

For j = 1 To 20

h(i, j) = i - j
If Abs(i - j) <> 1 Then h(i, j) = 0
Next j
Next i

Sheet1.Cells(1, 1).Resize(100, 100) = h
End Sub

Leandre1999
09-28-2020, 08:47 AM
Perfect thank you!