+ Reply to Thread
Results 1 to 3 of 3

Thread: Looping data entry macro

  1. #1
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    82

    Looping data entry macro

    Hi Everyone

    I want to use a piece of VBA to copy values from cells A1, C1, E1, and G1 and paste them into the next blank cell in an existing range called "DCopy". I am trying to use the following code, but as I have never tried writing a looping macro, have no idea what I am doing:

    Dim FirstCell As Range
    Dim FirstTargetCell As Range
    Dim i As Integer
    
    Set FirstCell = Sheets("Sheet1").Range("DEntry")
    Set FirstTargetCell = Sheets("Sheet1").Range("DCopy")
    i = 0
    
    Do
    FirstTargetCell.Offset(i, 0).Value = FirstCell.Offset(i, 0).Value
    i = i + 1
    Loop Until FirstCell.Offset(i, 0).Value = ""
    If I fire the macro above, it copies the cells, but pastes them into every cell in the "DCopy" range.

    Basically, I am trying to build a catalog, and want to enter the data in to the "DEntry" range, and have it copied to the next free line in the "DCopy" range.

    Does anyone have any ideas?
    Last edited by jiminic; 10-06-2008 at 07:13 PM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    You don't need a loop to do this. I can't see how your ode is finding the empty cell. Where is Dcopy? This will be more efficient & faster, you will have to amend the destination cells


    Dim R As Long
    
    R = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row + 1
    Cells(R, 1).Value = Cells(1, 1).Value
    Cells(R, 2).Value = Cells(1, 3).Value
    Cells(R, 3).Value = Cells(1, 5).Value
    Cells(R, 4).Value = Cells(1, 7).Value
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Registered User
    Join Date
    12-11-2006
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2007
    Posts
    82
    Thanks RoyUK, as usual you have saved my day!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Macro to copy down formulas adjacent to data.
    By highbury in forum Excel Programming
    Replies: 6
    Last Post: 04-30-2008, 06:55 AM
  2. Excle data file and macro publishing problem
    By sujata_ghosh in forum Excel Programming
    Replies: 0
    Last Post: 03-12-2008, 04:19 AM
  3. automatically find end of data using a macro
    By greaseman in forum Excel Programming
    Replies: 7
    Last Post: 02-27-2008, 10:23 AM
  4. Close after inactivity prevents data transfer macro.
    By dcwat in forum Excel Programming
    Replies: 1
    Last Post: 04-13-2007, 08:36 AM
  5. Macro to create new sheets from master data sheet
    By adsigel in forum Excel Programming
    Replies: 2
    Last Post: 10-04-2006, 09:21 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.2.0