VBA maco

Hello,

I need build simple macro for my excel file.
I want to repeat A1:F10 to the end of the sheet XEY1:XFD10



please help
h.
Book1.xlsx
henryk123Asked:
Who is Participating?
 
kgerbConnect With a Mentor Chief EngineerCommented:
Here is a more generalized version.  Simply input the starting cell and ending cell of the range you want to copy.  It will then copy the whole range as many times as it can before it runs out of columns.
Sub CopyToLastCol()
Dim FCell As Range, LCell As Range, cols As Long
Set FCell = Range("A10")
Set LCell = Range("F10")
cols = LCell.Column - FCell.Column + 1
With Range(FCell, LCell)
    .Copy Range(Cells(FCell.Row, LCell.Column + 1), Cells(FCell.Row, cols * Int((Columns.Count) / cols)))
End With
End Sub

Open in new window

Kyle
0
 
Patrick MatthewsCommented:
That worksheet has 16,384 columns.

16,384 is not evenly divisible by 6.
0
 
henryk123Author Commented:
copy and paste next 100 times
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
etech0Commented:
Try this. It'll take a while to run, though.


Sub copy()
'
' copy Macro
'

For x = 1 To 3000
    
    Range("A1:F10").copy
    Cells(1, x * 6 - 1).Select
    ActiveSheet.Paste
Next
End Sub

Open in new window

0
 
kgerbChief EngineerCommented:
I think this will do what you want.
Sub CopyA10F10()
Range("A10:F10").Copy Range("G10", Cells(10, 6 * Int((Columns.Count) / 6)))
End Sub

Open in new window

Kyle
0
 
etech0Commented:
you may have to adjust the 3000 to whatever number x it's up to when it errors at the end of the worksheet. click debug, hover over the x to see its value, and change 3000 to one less than that.
0
 
henryk123Author Commented:
thx, working great
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.