+ Reply to Thread
Results 1 to 10 of 10

copying lots of cells

  1. #1
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    copying lots of cells

    Hi everybody,

    I know Excel reasonably from the last few months but I had not done much VBA until recently so please bear with me.

    I have created a form using Excel that is a single A4 printable sheet, called Materials_Form. The data behind this form is stored in a single row in another sheet called Materials. I have created a Macro that when you select a row number from a cell at the top of the sheet then the rest of the information from the materials spreadsheet will be copied across. Now any changes can be made to the information by changing the cells and clicking save; the save process then writes this information back into the Materials spreadsheet for storing.

    My problem comes from the fact that the form has input boxes in random places on the sheet (for easy display of information) and as such you need to run a copy process for every cell to be copied (26 of them). This makes the macro fairly slow (6 seconds or so) as opposed to a single copy with some VBA array processing which I do not understand. I have used some named cells on the form so you can say
    [Date_Now] = Worksheets("Materials").Cells(dbRow, 2)
    and vice versa when saving form data,
    Worksheets("Materials").Cells(dbRow, 2) = [Date_Now]
    I have turned off ScreenUpdating but it is still slow, possibly because I have a quick check on whether the row number cell has changed at the top of the sheet. i.e. in order to update the form I update the Row number cell at the top and this triggers a cellchange which fills in the rest.

    I hope that makes sense and I would appreciate your help in speeding the code up please!

    Thanks,

    Chris
    Last edited by chrischarles; 06-28-2010 at 06:39 AM.

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    re: copying lots of cells

    ScreenUpdating will only speed up marginally. The major problem is usually selecting or activating sheets and ranges.

    It's hard to comment on improving code without seeing it, an example workbook would be useful
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    re: copying lots of cells

    Thanks very much for your response. Sorry I have attached one now but I had to strip out some information and put in some sample stuff.

    The worksheet will be shared when finished.

  4. #4
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    re: copying lots of cells

    Where's the attachment?

  5. #5
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    re: copying lots of cells

    It isnt letting me attach excel files for some reason, keeps giving me database errors. I am now trying a different browser and have zipped it up.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    re: copying lots of cells

    Seems to have attached above now. The code which I think is slowest are the Fill_In_Database and Fill_In_Form functions as these are the sections that require loads of copy operations...

    Thank you very much again.

  7. #7
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: copying lots of cells

    I can't see why that code should be slow.

  8. #8
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: copying lots of cells

    Damn, I was hoping there was a clever way of doing the copy process so that it is a single command and can be done much quicker in operation. I have tried a few ideas with copying a whole range and processing it using range.areas and range.areas.count but I cannot get them working.

    Would that not speed it up massively as I was hoping?

    Thanks again

  9. #9
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: copying lots of cells

    This code will be sufficient (and much faster)
    There's no need to use namedranges.
    In this example I filled in upto 'system2' (cell H7), that you will find in the code as cells(7,8).

    Please Login or Register  to view this content.

  10. #10
    Registered User
    Join Date
    06-28-2010
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    6

    Re: copying lots of cells

    Im not sure I really understand that code Im afraid. What does the resizing do? I have 22 items in my database row rather than 17 so should I change that? Also, I tried it with just the first 4 in place as you mentioned and it didnt do anything to the database so I can work out what it is setting when...

    Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.6.0 RC 1