+ Reply to Thread
Results 1 to 5 of 5

copying a whole row

  1. #1
    Registered User
    Join Date
    09-22-2006
    Posts
    39

    copying a whole row

    Hi

    I have the following code which copies the row from once sheet and copies it into another based on a value in a particular cell:

    For r = 1 To lastRow
    If LCase(sh1.Cells(r, 1)) = week Then
    rowSh2 = rowSh2 + 1
    sh1.Rows(r).Copy
    sh2.Select
    sh2.Cells(rowSh2, 1).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False

    weekTwo = True

    End If
    Next

    However, I don't want the whole row to be copied, only the first 23 columns. This is becuase I want to add data to the copied row in the new sheet and at the moment it wipes out all this data if I run the macro again.

    How can I code it so that it only copies a certain amount of columns in the row I am copying.

    Many Thanks

    Chris

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Chris,

    You can define which cells to copy by defining the Range.

    Change: sh1.Rows(r).Copy
    To: sh1.Range(Cells(r, 1), Cells(1, 23)).Copy

    This will copy Columns "A" through "W" only of row "r".

    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    01-09-2007
    Posts
    59
    This will do it

    Please Login or Register  to view this content.
    ska
    Last edited by ska67can; 01-26-2007 at 12:21 PM.

  4. #4
    Registered User
    Join Date
    09-22-2006
    Posts
    39
    Hi

    Thanks very much for the help so far. I have tried both methods you have mentioned but both seem to come up with the same error, namely a '400'. What does this mean?

    Any help would be appreciated

    Many Thanks

    Chris

  5. #5
    Registered User
    Join Date
    01-09-2007
    Posts
    59
    You'll have to post your whole code or better yet upload your spreadsheet so we can have a better look

    ska

+ 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