Excel Macro Loop / VBA code help

London 007

New Member
Joined
Mar 9, 2013
Messages
3
Hello,

Are there any Excel super stars that can help me?

I have never written any VBA code, but I think I need it for the following:

I wish to write a macro which has the following steps:
(1) Goes to a sheet called "Price Data"
(2) Copies a row of data (e.g. cells A2 to J2)
(3) Puts the copied data into a different sheet called "RSI Macro" in row 6
(4) Then runs a separate macro called "RSI Macro"
(5) Then repeats steps 1 to 4 for every row in the "Price Data" sheet that is not blank [e.g. takes data A3 to J3, then A4 to J4, and so on until all the rows with data have been completed]

I think this is called creating a row loop.

For your information the macro which I refer to in step (4) above is as follows (It may be better just to combine the two macros, rather than have two separate macros):

Macro1()
'
' Macro1 Macro
'


'
Sheets("RSI Macro").Select
Range("B6:DD6").Select
Selection.Copy
Range("C12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=True
Range("B3:CSubH3").Select
Application.CutCopyMode = False
Selection.Copy
Range("B12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=True
Range("A12:C203").Select
ActiveWindow.SmallScroll Down:=-282
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Add Key:=Range( _
"B12:B99"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("RSI Macro").Sort
.SetRange Range("A12:C99")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("B18").Select
ActiveWindow.SmallScroll Down:=3
ActiveWindow.SmallScroll ToRight:=-1
ActiveWindow.SmallScroll Down:=4
ActiveWindow.SmallScroll ToRight:=-2
ActiveWindow.SmallScroll Down:=41
ActiveWindow.SmallScroll ToRight:=-1
ActiveCell.Offset(51, 2).Range("A1:G1").Select
Selection.AutoFill Destination:=ActiveCell.Range("A1:G3"), Type:= _
xlFillDefault
ActiveCell.Range("A1:G3").Select
Range("D59").Select
ActiveWindow.SmallScroll Down:=-42
Range("B12:B91").Select
Selection.Copy
Range("M12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("C12:C127").Select
Application.CutCopyMode = False
Selection.Copy
ActiveWindow.SmallScroll Down:=-271
Range("N12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("M12:N120").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Add Key:=Range( _
"M12:M120"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("RSI Macro").Sort
.SetRange Range("M12:N120")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("M10:O177").Select
Selection.ClearContents
Range("B12:B101").Select
Selection.Copy
Range("M12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("J12:J137").Select
Application.CutCopyMode = False
Selection.Copy
Range("N12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Range("M12:N118").Select
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("RSI Macro").Sort.SortFields.Add Key:=Range( _
"M12:M118"), SortOn:=xlSortOnValues, Order:=xlDescending, DataOption:= _
xlSortNormal
With ActiveWorkbook.Worksheets("RSI Macro").Sort
.SetRange Range("M12:N118")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Range("N12:N108").Select


Many thanks,

James
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
suppose the data is ike this in sheet called "PRICE DATA" (ANOTHER SHEET IS CALLED rsi mACRO")

Price Data

*ABCDEFGHIJ
1hdng1hdng2hdng3hdng4hdng5hdng6hdng7hdng8hdng9hdng10
276232021913648477157
32692881114543494356
484179972631615537336
59851661423693231325
6452615290323656313
75183608482783982145
894992184732557823125
948535666624673765547
10720734456463447237

<colgroup><col style="font-weight:bold; width:30px; "><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"><col style="width:64px;"></colgroup><tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4


Your macri is from recorded macro. That is perfectly right for learning how to write a macro. But the RECORDED macro can be tweaked.

now see this macro (and check with your macro)

Code:
Sub test()
Dim lastcell As Range


With Worksheets("price data")
Set lastcell = .Range("J2").End(xlDown)
.Range(Range("A2"), lastcell).Copy
With Worksheets("rsi macro")
.Range("a6").PasteSpecial
End With
End With
 
Upvote 0

Forum statistics

Threads
1,215,475
Messages
6,125,028
Members
449,205
Latest member
Eggy66

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