+ Reply to Thread
Results 1 to 11 of 11

Looping through sheets help

  1. #1
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Looping through sheets help

    Hi,
    The following loop works as intended
    Please Login or Register  to view this content.
    it loops through each spreadsheet in the workbook, putting the name of the sheet in A2.

    The loop below DOES NOT work as intended.

    Please Login or Register  to view this content.
    it loops through the code correctly, but ON THE SAME SHEET, not looping THROUGH the sheets. It just keep coping D and E to F, deleting D and E, over and over on the same sheet.

    what is the problem?

    thanks.

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Looping through sheets help

    You are missing worksheet references for Columns, Range etc.

    Try this.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    Thanks Norie. This appears to be working.
    What I'm really trying to do is loop through all worksheets in a workbook, find the words Volume and Revenue in the header row, copy and paste those columns to the column after the last column of data (lastusedcolumn+1) and delete the original columns.

    below is my attempt, but it just loops through the columns on one spreadsheet again.
    Please Login or Register  to view this content.
    Quote Originally Posted by Norie View Post
    You are missing worksheet references for Columns, Range etc.

    Try this.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    ok I can get it to do everything I need except copy the entire column. It just copies the header into the first column after the last column of data. also i can't get it to delete the original "volume" column.


    Please Login or Register  to view this content.

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Looping through sheets help

    Does this work?
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    Thanks. It works on some of the sheets but not all. Also, it's deleting thewrong column. I want to rename the new Volume column "Total Volume" and remove the old "volume" column.

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Looping through sheets help

    Is there always a volume column on a worksheet?

    Can you attach a sample workbook?

  8. #8
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    yes. There are about ten worksheets with silmilar column headings. All Have a Volume and Revenue Column. It's an export from an Access crosstab, so the volume and revenue totals are in the wrong place. I want them at the end of the other colums.

    Quote Originally Posted by Norie View Post
    Is there always a volume column on a worksheet?

    Can you attach a sample workbook?

  9. #9
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    I can't get the file to upload. Sorry

    edit: it's also coping and pasting the wrong volume column. I actually don't know what it's pasting!
    Last edited by apunc1; 01-31-2013 at 02:30 PM.

  10. #10
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    The vbscript below works for one sheet only. When I try to loop the sheets, the loop doesn't work so that's why i'm trying to do this in VBA. I was trying to follow the basic structure of the vbscript, since it works, but add the looping sheets.

    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    10-17-2012
    Location
    nc
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Looping through sheets help

    this code does what i want. I had curCol defined incorrectly, so it was doing weird things. thanks for your help.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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