My goal is to use the range objects from subroutine A toexecute subroutine B. To do this, I’d like to combine subroutine B intosubroutine A.
I was going to attach the spreadsheet to show you what I mean, but I don't have permissions to do that. Basically, if you could help me on my syntax (I underlined what I mean), I'm sure this will work.
I also posted both subroutines below as a quick overview, with my notes throughout. While I think I understand what needs to happen, the syntax is killing me . The code is as follows (Any help would be appreciated):
<strike></strike>
I was going to attach the spreadsheet to show you what I mean, but I don't have permissions to do that. Basically, if you could help me on my syntax (I underlined what I mean), I'm sure this will work.
I also posted both subroutines below as a quick overview, with my notes throughout. While I think I understand what needs to happen, the syntax is killing me . The code is as follows (Any help would be appreciated):
<strike></strike>
Code:
Option Explicit
Sub A_Subtotal()
[/COLOR][COLOR=#ff0000]'Step1: Select "A14" for the first inputbox(EXAMPLE ONLY)[/COLOR]
[COLOR=#ff0000][/COLOR]
[COLOR=#ff0000]'Step2: Select "A15:A22" for the second inputbox(EXAMPLE ONLY)[/COLOR]
[COLOR=#000000]
On Error Resume Next
Dim X, Y, Z As Object
Dim I As Long
Set X =Application.InputBox(Prompt:="Select a cell from the desired break.",Title:="X-Axis.", Type:=8)
Set Y =Application.InputBox(Prompt:="Select y-axis range. Avoid mergedcells.", Title:="Y-Axis.", Type:=8)
If X Is Nothing Then Exit Sub
For I = 13 To 33
Cells(X.Row, I).Value = WorksheetFunction.Sum(Y.Offset(, I + (1 -Y.Column) - 1))
Next I
On Error GoTo 0
End Sub
Sub B_Sort()
[/COLOR][COLOR=#ff0000]'Step1: Select "A15:AG22" (EXAMPLE ONLY)[/COLOR]
[COLOR=#ff0000][/COLOR]
[COLOR=#ff0000]'PROBLEM: Use the range objects from subroutine A to executeSubroutine B.[/COLOR]
[COLOR=#ff0000][/COLOR]
[COLOR=#ff0000]'NOTE: I must ensure the user can define the range objects via theinput boxes since the row numbers are always dynamic.[/COLOR]
[COLOR=#000000]
Dim Z As Object
Set Z = Application.InputBox(Prompt:="Select a cellfrom the desired break.", Title:="X-Axis.", Type:=8)
[/COLOR][U][B][COLOR=#ff0000]' The range to sort will always be Range("A" &X.Row & ":AG" & Y.Row) with x.row offset down 1 (I can't seemto get my syntax right when writing this).[/COLOR][/B][/U]
[U][B][COLOR=#ff0000][/COLOR][/B][/U]
[U][B][COLOR=#ff0000]' The key range will always be M Column with X.Row offsetdown 1 to Y.Row. The same thing will then be used for each column with AGcolumn being the last one.[/COLOR][/B][/U]
[COLOR=#000000]
Z.SortKey1:=Range("M15:M22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("N15:N22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("O15:O22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("P15:P22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("Q15:Q22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("R15:R22"), Order1:=xlAscending, dataoption1:=xlSortNormal
Z.SortKey1:=Range("S15:S22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("T15:T22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("U15:U22"), Order1:=xlAscending, dataoption1:=xlSortNormal
Z.SortKey1:=Range("V15:V22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("W15:W22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("X15:X22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.Sort Key1:=Range("Y15:Y22"),Order1:=xlAscending, dataoption1:=xlSortNormal
Z.SortKey1:=Range("Z15:Z22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("AA15:AA22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("AB15:AB22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("AC15:AC22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("AD15:AD22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.Sort Key1:=Range("AE15:AE22"),Order1:=xlAscending, dataoption1:=xlSortNormal
Z.SortKey1:=Range("AF15:AF22"), Order1:=xlAscending,dataoption1:=xlSortNormal
Z.SortKey1:=Range("AG15:AG22"), Order1:=xlAscending,dataoption1:=xlSortNormal
End Sub