telecomjohnny
New Member
- Joined
- Aug 30, 2022
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
Rookie vba user/poster
ASK: VBA macro that combines/stacks multiple (3 column ranges) into a single 3 column stack.
The macro needs to dynamically find the next available row in order to paste-special/values of the 2nd, 3rd, 4th (3 column range sets)
example data set A
Ranges (note: all ranges are formulas/not static values)
$S2:$U15 (14 rows) refer to as range 2
$X2:$Z37 (36 rows) range 3
$AC2:$AE9 (8 rows) range 4
Total of 58 rows
Combine the data of the three 3 column ranges by, copy/paste special-Values, into a separate single 3 column range stack $N:$P 58 rows total
The problem I'm having is that the macro is NOT dynamically finding the NEW ROW LENGTHS of the (3 column ranges) that need to be stacked into $N:$P
example data set B
$S2:$U52 (51 rows) range 5 (The macro was recorded on Data set A, running the macro on this new data B only pastes 14 rows and NOT 51.)
$X2:$Z30 (15 rows) range 6
$AC2:$AE2 (15 rows) range 7
Total of 81 rows
***********copy of my macro *********
Sub Construct()
'
' Construct Macro
Sheets("Order + Phase 1").Select
Range("M2:P2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Clear
'copy Range 2 ESRK "$S2:$U?"
Range("S2:U2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Paste "Range 2" ESRK into Construct "Colnm N"
Range("N2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 3 ESRK
Range("X2:Z2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
'****this is next step is NOT WORKING!!!! *****************************************************************************
Range("N16").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 4 ESRK
Range("AC2:AE2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O2").Select
Selection.End(xlDown).Select
Range("N52").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 5 ESRK
Range("AH2:AJ2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N60").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll ToRight:=14
'copy Range 6 ESRK
Range("AM2:AO2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N108").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ScrollColumn = 33
'copy Range 7 ESRK
Range("AR2:AT2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N123").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ASK: VBA macro that combines/stacks multiple (3 column ranges) into a single 3 column stack.
The macro needs to dynamically find the next available row in order to paste-special/values of the 2nd, 3rd, 4th (3 column range sets)
example data set A
Ranges (note: all ranges are formulas/not static values)
$S2:$U15 (14 rows) refer to as range 2
$X2:$Z37 (36 rows) range 3
$AC2:$AE9 (8 rows) range 4
Total of 58 rows
Combine the data of the three 3 column ranges by, copy/paste special-Values, into a separate single 3 column range stack $N:$P 58 rows total
The problem I'm having is that the macro is NOT dynamically finding the NEW ROW LENGTHS of the (3 column ranges) that need to be stacked into $N:$P
example data set B
$S2:$U52 (51 rows) range 5 (The macro was recorded on Data set A, running the macro on this new data B only pastes 14 rows and NOT 51.)
$X2:$Z30 (15 rows) range 6
$AC2:$AE2 (15 rows) range 7
Total of 81 rows
***********copy of my macro *********
Sub Construct()
'
' Construct Macro
Sheets("Order + Phase 1").Select
Range("M2:P2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Clear
'copy Range 2 ESRK "$S2:$U?"
Range("S2:U2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
'Paste "Range 2" ESRK into Construct "Colnm N"
Range("N2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 3 ESRK
Range("X2:Z2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
'****this is next step is NOT WORKING!!!! *****************************************************************************
Range("N16").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 4 ESRK
Range("AC2:AE2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O2").Select
Selection.End(xlDown).Select
Range("N52").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
'copy Range 5 ESRK
Range("AH2:AJ2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N60").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.SmallScroll ToRight:=14
'copy Range 6 ESRK
Range("AM2:AO2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N108").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
ActiveWindow.ScrollColumn = 33
'copy Range 7 ESRK
Range("AR2:AT2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Copy
Range("O1").Select
Selection.End(xlDown).Select
Range("N123").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False