How to repeat VBA and paste result in next row

Alex_Lim

New Member
Joined
Jan 28, 2019
Messages
1
Hi am new to vba. How to repeat the commands below and paste results in row C8, C9, etc. Thanks.
'
Sheets("Rand").Select
Range("A1").Select
Calculate
Range("A1:A8").Select
Selection.Copy
Range("A12").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Worksheets("Rand").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("Rand").Sort.SortFields.Add2 Key:=Range("A12:A19") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Rand").Sort
.SetRange Range("A12:A19")
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Selection.Copy
Sheets("MLife").Select
Range("C7").Select
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=True
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try with this


Code:
Sub Copy_Paste()
    Sheets("Rand").Select
    'Range("A1").Select
    'Calculate
    Range("A1:A8").Copy
    Range("A12").PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
    With ActiveWorkbook.Worksheets("Rand").Sort
        .SortFields.Clear
        .SortFields.Add Key:=Range("A12:A19"), SortOn:=xlSortOnValues, _
            Order:=xlAscending, DataOption:=xlSortNormal
        .SetRange Range("A12:A19")
        .Header = xlGuess
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
    Range("A12:A19").Copy
    Sheets("MLife").Select
    u = Range("C" & Rows.Count).End(xlUp).Row + 1
    Range("C" & u).PasteSpecial Paste:=xlPasteAll
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

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