+ Reply to Thread
Results 1 to 7 of 7

Copying rows to another worksheet

  1. #1
    Registered User
    Join Date
    08-21-2007
    Posts
    4

    Copying rows to another worksheet

    Hello all,

    I had a question about excel macros and VBA. So I have a sheet of raw data within an excel workbook. I already created a macro to create new worksheets. What I want to do is iterate through the raw data and depending on a value in a certain column, I want to copy that row to another worksheet. I think I know the beginning and the end, but I cant figure out how to iterate through the rows.

    Any help would be much apprecieated.

    Thanks!

  2. #2
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    solidgold10287

    Maybe something like this would get you started.
    Please Login or Register  to view this content.
    Sincerely,
    Jeff

  3. #3
    Registered User
    Join Date
    08-21-2007
    Posts
    4
    Thanks for the quick response. This is what I have but for some reason it keeps throwing this error:

    Run-time error '9':
    Subscript out of range

    It happens right when I try to set wsDefense equal to Sheets("Sheet2"). What am i doing wrong?


    Please Login or Register  to view this content.
    I also tried to do wsDefense = Sheets("Defense"), but for some reason i get this error:

    Run-Time error '91':
    Object variable or with block variable not set


    I dont know where to go from here on either of these problems.

    Thanks
    Last edited by solidgold10287; 08-21-2007 at 01:57 PM.

  4. #4
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    solidgold10287,

    I apologize I was a little to quick with my response. I left the work "Set" off of my response.

    These
    Please Login or Register  to view this content.
    all need the word Set in front. For example
    Please Login or Register  to view this content.
    Make that change and see what happens. Sorry for the error.

  5. #5
    Registered User
    Join Date
    08-21-2007
    Posts
    4
    Ahh thank you. Works like a charm

  6. #6
    Registered User
    Join Date
    08-21-2007
    Posts
    4
    One more thing, how would I access a certain column. I dont know the syntax. I'm assuming it would be something like:

    lRow.Columns(index of column needed)

    I've been looking but I cant find much on it.

  7. #7
    Forum Contributor boylejob's Avatar
    Join Date
    02-22-2007
    Location
    Forest City, NC
    MS-Off Ver
    2003
    Posts
    562
    solidgold10287,

    I'm not sure I understand your question. What do you mean by access a certain column? Do you mean you want to look at a specific cell on each row as you are looping thru. In other words, are you wanting to look at the value in column G of whatever row you are on.

    If this is what you are wanting to do then any of these would reference a particular cell on the row (lRow) you are on.
    Please Login or Register  to view this content.
    If this does not help, be a little more specific and I'll see if I can give you a better answer.

+ 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