copy the values from one sheet and pasting it to other skipping rows

Suchi D

New Member
Joined
May 22, 2015
Messages
5
Hi,

I am new to VBA. I am trying to do one thing regarding copy and paste. Here is my question.


I want to count the number of values in the column A of sheet1 and want to paste them in the column D of Sheet 2 skipping 7 rows.
pattern goes like:
sheet1.A2 copy and pasted to sheet2.D2
sheet1.A3 copy and pasted to Sheet2.D9
sheet1.A4 copy and pasted to Sheet2.D16 and so..with the difference of 7.

Can anyone please help me with it?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Hi,

Try this code.


Code:
Sub somesub()
Dim LastRow As Long, C As Range
Dim Myrange As Range, x As Long
Dim Src As Worksheet, Dst As Worksheet
Set Src = Sheets("Sheet1")
Set Dst = Sheets("Sheet2")
LastRow = Src.Cells(Rows.Count, "A").End(xlUp).Row
Set Myrange = Src.Range("A2:A" & LastRow)
x = 2
For Each C In Myrange
C.Copy Dst.Range("D" & x)
x = x + 7
Next
End Sub
 
Upvote 0
Hi, There is one more issue. This code is copying the range. But if I want to copy the range which consists of formulas, but I only want the values to be copied. then how can I make the changes in this code, if in sheet1 A2 to A. lastrow is a range of formulas?
 
Upvote 0
Try:
Code:
Sub Macro1()

Dim LR      As Long
Dim x       As Long: x = 2
Dim rngItr  As Excel.Range
Dim rngSrc  As Excel.Range

Application.ScreenUpdating = False

With Sheets("Sheet1")
    LR = .Cells(.Rows.Count, 1).End(xlUp).Row
    Set rngSrc = .Range("A2").Resize(LR-1)
End With

With Sheets("Sheet2")
    For Each rngItr In rngSrc
        .Range("D" & x).Value = rngItr.Value
        x = x + 7
    Next rngItr
End With

Set rngItr = Nothing
Set rngSrc = Nothing

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Hi, There is one more issue. This code is copying the range. But if I want to copy the range which consists of formulas, but I only want the values to be copied. then how can I make the changes in this code, if in sheet1 A2 to A. lastrow is a range of formulas?

Hi,

Like this

Code:
Sub somesub()
Dim LastRow As Long, C As Range
Dim Myrange As Range, x As Long
Dim Src As Worksheet, Dst As Worksheet
Set Src = Sheets("Sheet1")
Set Dst = Sheets("Sheet2")
LastRow = Src.Cells(Rows.Count, "A").End(xlUp).Row
Set Myrange = Src.Range("A2:A" & LastRow)
x = 2
For Each C In Myrange
Dst.Range("D" & x).Value = C.Value
x = x + 7
Next
End Sub
 
Upvote 0
Also, If I just want a shortcut to run these macro then what can be done? for now, I am going to View Macro and then executing the macros.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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