Consulting

Results 1 to 3 of 3

Thread: Run time error 438

  1. #1

    Run time error 438

    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:


    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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    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
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Perfect thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •