'Subscript out of range' problem when calling a sub from a different sheet

Blaise

New Member
Joined
Sep 25, 2011
Messages
14
Dear Experts,

Unfortunately I'm not good at vba coding and I cannot figure out why the last Call in the following code does not work and gives a "Runtime error '9' - Subscript out of range" error.
The macro to be called runs perfectly when started manually.

Here is the main code:

Code:
Sub CommandButton1_Click()


    Worksheets("NyersanyagRaktár").Range("G6:G100").Value = Worksheets("NyersanyagBeszerzés").Range("C6:C100").Value
    
    Worksheets("NyersanyagRaktár").Range("B6:B100").Value = Worksheets("NyersanyagRaktár").Range("E6:E100").Value


    Worksheets("NyersanyagRaktár").Range("C6:C100").Value = Worksheets("NyersanyagRaktár").Range("I6:I100").Value
    
    Worksheets("BeszerzésTemp").Range("A6:J100").Value = Worksheets("NyersanyagBeszerzés").Range("A6:J100").Value
    
    Range("C6:E100").Select
    Selection.ClearContents


    Range("H6:I100").Select
    Selection.ClearContents
    
    Worksheets("Nyersanyagraktár").Activate
    Worksheets("Nyersanyagraktár").Range("G6.G100").Select
    Selection.ClearContents
    
   
    Call Sheet17.Purchasedelrowsifzero
    
    Application.CopyObjectsWithCells = False
    ActiveWorkbook.Sheets("BeszerzésTemp").Copy
    
    Call Sheet17.SaveUnique
    
    Call Sheet17.CopyStuff
    
    Call Sheet19.NyersStockSort
    
End Sub

And this is the NyersStockSort macro on Sheet19:

Code:
Public Sub NyersStockSort()


    ActiveWorkbook.Worksheets("NyersanyagRaktarTeteles").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("NyersanyagRaktarTeteles").Sort.SortFields.Add Key _
        :=Range("B6:B300"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("NyersanyagRaktarTeteles").Sort.SortFields.Add Key _
        :=Range("J6:J300"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("NyersanyagRaktarTeteles").Sort
        .SetRange Range("B6:J300")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    
End Sub

Any help would be highly appreciated.

All the best,
Balazs
 
Last edited by a moderator:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
That doesn't really answer my question, I'm afraid. Which line is highlighted by the debugger?

As a matter of interest, why are you putting routines into worksheet modules and making them public instead of putting them in normal modules where they appear to belong?
 
Upvote 0
Which specific line causes the error?

Please note the closing code tag is [/code] and not [\code]

Ooops, I'm sorry for the mistype.

The 'RawStockdelrowsifzero' code does the job, but the 'CopyRawUsage' does not start. The error window says: "Runtime error 438. Object doesn't support this property or method."
I've just noticed that it's not the same error, I might have started a new thread.
 
Upvote 0
I just spotted it. This line:

Rich (BB code):
Worksheets("RawStockUsage_Temp").Range("A1:B500").ClearContent

should read:

Rich (BB code):
Worksheets("RawStockUsage_Temp").Range("A1:B500").ClearContents
 
Upvote 0
I just spotted it. This line:

Rich (BB code):
Worksheets("RawStockUsage_Temp").Range("A1:B500").ClearContent

should read:

Rich (BB code):
Worksheets("RawStockUsage_Temp").Range("A1:B500").ClearContents

Rory for President !! :) You are awesome. I would have never noticed this. Thank you.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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