473,322 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

VBA for MS Excel - Copy, then Paste Loop Until End of Document

VBA for MS Excel - Copy, then Paste Loop Until End of Document

I need to copy text in row 1 and paste into row 2, and Loop paste into row 4, row 6, row 8, row 10, ect.
Mar 23 '10 #1

✓ answered by SammyB

Does this do what you want?
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Sub Macro1()
  3.     ' Determine last row
  4.     Dim n As Integer, i As Integer
  5.     n = Cells.SpecialCells(xlCellTypeLastCell).Row
  6.     ' Copy the odd rows to the next row
  7.     For i = 1 To n Step 2
  8.         Rows(i).Copy Rows(i + 1)
  9.     Next i
  10. End Sub

4 8104
SammyB
807 Expert 512MB
Does this do what you want?
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2. Sub Macro1()
  3.     ' Determine last row
  4.     Dim n As Integer, i As Integer
  5.     n = Cells.SpecialCells(xlCellTypeLastCell).Row
  6.     ' Copy the odd rows to the next row
  7.     For i = 1 To n Step 2
  8.         Rows(i).Copy Rows(i + 1)
  9.     Next i
  10. End Sub
Mar 23 '10 #2
@MicheleDavidson
YES, thank you soooo much, you saved me a lot of time.

Can I use the same Macro to copy formulas in row 3 columns 5 & 6 and paste into all of the odd number rows until the end of the document?
Mar 23 '10 #3
SammyB
807 Expert 512MB
Somewhat the same:
Expand|Select|Wrap|Line Numbers
  1. Sub Macro2()
  2.     ' Determine last row
  3.     Dim n As Integer, i As Integer
  4.     n = Cells.SpecialCells(xlCellTypeLastCell).Row
  5.     ' Copy cells E3:F3 into the odd rows
  6.     For i = 5 To n Step 2
  7.         Range("E" & i & ":F" & i).FormulaR1C1 = Range("E3:F3").FormulaR1C1
  8.     Next i
  9. End Sub
Mar 23 '10 #4
Yes it worked great! Your Awesome! Thank you sooo much, I really appreciate it!!
Mar 23 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Faith | last post by:
Hello. I need to take a column from Excel(unknown amount of rows) that will be selected by the user and copy those cells. Then I will need to paste those cells into the first column in a Data...
2
by: Mansi | last post by:
I'm trying to automate excel from c#. One of the things I need to do is to copy/paste/insert rows in excel via c# code. I tried to do the following: 1) Select a row in excel (a12 to k12) 2)...
7
by: lgbjr | last post by:
Hello All, I¡¯m using a context menu associated with some pictureboxes to provide copy/paste functionality. Copying the image to the clipboard was easy. But pasting an image from the clipboard...
1
by: Lloyd Dupont | last post by:
I'm implementing my own, custom, internationalized text editor. I'm trying to implement copy/paste right now. Which cause me some trouble. I'm using .NET 2.0 beta 2 (I have ordered and I'm waiting...
7
by: VoTiger | last post by:
Hi everyone, i am ttrying to find a way to do the copy / paste between an existing excel file and my flexgrid (in runtime application). But the fact is that i don't know how to proceed. The...
0
by: Nicholas Dreyer | last post by:
Operating System: Microsoft Windows Version 5.1 (Build 2600.xpsp_sp2_gdr.050301-1519 : Service Pack 2) Visual Basic: MIcrosoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 Forms3:...
0
by: six888 | last post by:
i need to make a report using excel. im given a few data in excel document for a 1 month report (1 document for each week). each data document have a few work sheet.i need only certain information in...
2
by: shogot99 | last post by:
Till here the info gotten is ok Loop Until strainfo = "" ScreenMNS.WaitHostQuiet (400) Second process Copy "B" & paste in "E" Range("B2:B600").Select
2
by: OfficeDummy | last post by:
Hi, everyone! Like I mentioned in the thread title, I need to copy&paste data between different workbooks, and it works fine. However, when the data has been copied to the destination workbook,...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.