Range loop copy and paste vba macro problem

badsha001

New Member
Joined
Jan 30, 2013
Messages
4
I search everywhere but unfortunately i cant find the solution. So what i have is range "K4:M408". wht i m doing is looping but i want to change range. i will start from Range(K4:M7) and then (K8:M11) and then (K12:K15). please help me how can i do it



Code:
Sheets("Sheet1").Select
   Range("K4:M7").Select                                    
   Selection.Copy
    Sheets("sheet1").Select
    Range("A2").Select
    ActiveSheet.Paste

  i have some macro here,it will run and then now i want to repeat exactly samething again but want to change the range only.

Range("K8:M11").Select                                    
   Selection.Copy
    Sheets("sheet1").Select
    Range("A2").Select
    ActiveSheet.Paste
i ahve some macro here and then now i want to repeat exactly samething again but want to change the range only.

Range("K12:M15").Select                                    
   Selection.Copy
    Sheets("sheet1").Select
    Range("A2").Select
    ActiveSheet.Paste
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Actually i want to paste into A2 everytime, In sheet 1 i have macro which provide me the coefficient based on the value from sheet2 range (k4:m7), (k8,m11).... I record the value into next sheet3 now i want it to go back to next range.
 
Last edited:
Upvote 0
Try:

Code:
Sub Test()
    Dim r As Long
    For r = 4 To 408 Step 4
        Worksheets("Sheet1").Range("K" & r).Resize(4).Copy Worksheets("Sheet1").Range("A2")
    Next r
End Sub
 
Upvote 0
This is exactly what i want but its only copying from K column i want to copy from L and M column too. My range is K4:M408 not K4:K408. Thanks in advance

Code:
Sub Test()    
Dim r As Long    For r = 4 To 408 Step 4        
Worksheets("Sheet1").Range("K" & r).Resize(4).Copy Worksheets("Sheet2").Range("A2")   
 Next r
End Sub
</PRE>
 
Upvote 0
Actullay problem solved, thanks for everyone.

What i did basically is that

Code:
Sub Test() 
Dim r As Long For r = 4 To 408 Step 4 
Worksheets("Sheet1").Range("K" & r).Resize(4).Copy Worksheets("Sheet2").Range("A2") 
Worksheets("Sheet1").Range("l" & r).Resize(4).Copy Worksheets("Sheet2").Range("b2")
Worksheets("Sheet1").Range("m" & r).Resize(4).Copy Worksheets("Sheet2").Range("c2") 
Next r
End Sub

</PRE>
 
Upvote 0
You could have used:

Rich (BB code):
Sub Test()
    Dim r As Long
    For r = 4 To 408 Step 4
        Worksheets("Sheet1").Range("K" & r).Resize(4, 3).Copy Worksheets("Sheet1").Range("A2")
    Next r
End Sub
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,120
Members
451,399
Latest member
alchavar

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