+ Reply to Thread
Results 1 to 7 of 7

looping from worksheet to worksheet

  1. #1
    Registered User
    Join Date
    03-19-2018
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    27

    looping from worksheet to worksheet

    Hi there
    I am trying to run a row delete macro on all worksheets in an Excel document and I can't get it to work. I tried select all sheets and running the macro and all creating a loop and running it but the only thing that seems to be working is the row unhide and not the delete rows based on a cell Value. It's only grabbing the first worksheet and running the delete row based on cell value. Can anyone help? Here is the start of my macro.

    Dim ws As Worksheet
    For Each ws In ActiveWorkbook.Worksheets
    With ws
    .Rows("1:5000").Hidden = False
    End With
    Next ws

    For Each ws In ActiveWorkbook.Worksheets
    With ws
    With Range("D1", Range("D" & Rows.Count).End(xlUp))
    .AutoFilter Field:=1, Criteria1:="*SOLD*"
    .Offset(1).EntireRow.Delete
    .AutoFilter
    End With
    Next ws

    End Sub


    End Sub
    Last edited by Melissalee71; 04-13-2018 at 11:40 AM.

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: looping from worksheet to worksheet

    Missing leadng periods.

    Please Login or Register  to view this content.
    Last edited by AlphaFrog; 04-13-2018 at 11:41 AM.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    03-19-2018
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    27

    Re: looping from worksheet to worksheet

    Quote Originally Posted by AlphaFrog View Post
    Missing leadng periods.

    Please Login or Register  to view this content.
    IT WORKS!! Thanks

    What do the leading periods accomplish because my code worked before but just not when I tried to "loop" it worksheet to worksheet?

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: looping from worksheet to worksheet

    Quote Originally Posted by Melissalee71 View Post
    IT WORKS!! Thanks

    What do the leading periods accomplish because my code worked before but just not when I tried to "loop" it worksheet to worksheet?
    You're welcome.

    The leading periods reference back to the WS object in the previous With statement. Without the periods, the two Range references have no qualified worksheet. So they default to the Active sheet which doesn't change in your macro. With the periods, the two range references use the WS object in the With statement.

  5. #5
    Registered User
    Join Date
    03-19-2018
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    27

    Re: looping from worksheet to worksheet

    Quote Originally Posted by AlphaFrog View Post
    You're welcome.

    The leading periods reference back to the WS object in the previous With statement. Without the periods, the two Range references have no qualified worksheet. So they default to the Active sheet which doesn't change in your macro. With the periods, the two range references use the WS object in the With statement.
    Ok, I kind of get it - but what about this one then?

    For Each ws In ActiveWorkbook.Worksheets
    With ws
    With .Range.Columns(1).Cells 'change column as needed for macro
    If IsEmpty(cell) = True Then cell.Select: Exit For
    Next cell
    ActiveCell.Offset(1, 2).Select
    End With
    End With
    Next ws

  6. #6
    Registered User
    Join Date
    03-19-2018
    Location
    Chicago
    MS-Off Ver
    2016
    Posts
    27

    Re: looping from worksheet to worksheet

    what I am trying to accomplish with the last macro is to:

    Select END of data in column A
    Then down one cell
    Then over 2 cells.

    I want to paste a "blurb" into that cell on each worksheet. Each worksheet will be a different cell.

    I can't figure it out.

  7. #7
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: looping from worksheet to worksheet

    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)

Similar Threads

  1. Help looping through all worksheet please!
    By ahazeldene in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-28-2017, 07:47 AM
  2. need help with looping through worksheet
    By gurtejhira in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-24-2015, 04:38 PM
  3. looping thru all columns in a worksheet
    By kawi125 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-01-2006, 10:50 AM
  4. Looping through crosstab worksheet
    By jpendegraft in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-24-2006, 07:26 PM
  5. [SOLVED] Looping Checkboxes on Worksheet
    By Robbyn in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-07-2005, 05:05 PM
  6. [SOLVED] looping thru the worksheet
    By cadcamguy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-29-2005, 03:05 PM
  7. [SOLVED] Looping Through Worksheet
    By lark in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-12-2005, 12:06 PM

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