How to combine several sub test codes in Excel.

BBAmog

New Member
Joined
Jan 19, 2017
Messages
8
Hi. I previously got help with a code. I modified it to use it several times, about 10 times. The question is:

1. Instead of pasting the code for every single operation and run it, i want to paste them all and run. The code is two ex:

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next
End Sub

Thanks!
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
hi! you want something like this?

Rich (BB code):
Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next

End Sub

 
Upvote 0
Hi. I previously got help with a code. I modified it to use it several times, about 10 times. The question is:

1. Instead of pasting the code for every single operation and run it, i want to paste them all and run. The code is two ex:

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next
End Sub

Thanks!

I am a little confused on what you want done, but I believe that you want to copy from sheet "Ark1" and paste into sheet "Ark2". Your question seems to be how to paste the values into both column A and B at the same time. If so, try the following:

Code:
Sub test3()
Dim rng As Range, i As Long
Dim lngROW As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i, "B" & i)
i = i + 50
Next

'Range("E4,G4").Select
End Sub

Also when posting code please use code tags. much easier to read and reduces scrolling!

code tags are:

opening code with = [ code ]
closing code with = [ /code ]

Both with out any spaces.
 
Last edited:
Upvote 0
Hi again. Maybe I was not clear enough. I have the same code but for different cells. About ten times. Now I am pasting the code in excel, run it, and does this ten times, one per code. Is there not an easier way to paste all the codes at the same time and run them? my codes are:

Code:
Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("A3:A" & Sheets("Ark1").Range("A" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("B3:B" & Sheets("Ark1").Range("B" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("C" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 3
For Each rng In Sheets("Ark1").Range("Z3:Z" & Sheets("Ark1").Range("Z" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("G" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 47
For Each rng In Sheets("Ark1").Range("Z3:Z" & Sheets("Ark1").Range("Z" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 5
For Each rng In Sheets("Ark1").Range("D3:D" & Sheets("Ark1").Range("D" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("C" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 5
For Each rng In Sheets("Ark1").Range("C3:C" & Sheets("Ark1").Range("C" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("D" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 5
For Each rng In Sheets("Ark1").Range("Q3:Q" & Sheets("Ark1").Range("Q" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("F" & i)
i = i + 50
Next
End Sub
 

Sub test()
Dim rng As Range, i As Long
i = 5
For Each rng In Sheets("Ark1").Range("C3:C" & Sheets("Ark1").Range("C" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("G" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 9
For Each rng In Sheets("Ark1").Range("V3:V" & Sheets("Ark1").Range("V" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("A" & i)
i = i + 50
Next
End Sub

Sub test()
Dim rng As Range, i As Long
i = 37
For Each rng In Sheets("Ark1").Range("U3:U" & Sheets("Ark1").Range("U" & Rows.Count).End(xlUp).Row)
rng.Copy Sheets("Ark2").Range("B" & i)
i = i + 50
Next
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
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