+ Reply to Thread
Results 1 to 3 of 3

How to skip empty sheet?

Hybrid View

  1. #1
    Forum Contributor VAer's Avatar
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    803

    How to skip empty sheet?

    Runtime error 1004, No cells found. Since there is a empty sheet (a sheet with nothing)

    Below is just sample code.

    Sub removeextraspace()
    
    Dim WS As Worksheet
    Dim WB As Workbook
    Dim aCell As Range
    
    Application.ScreenUpdating = False
    
    ThisWorkbook.Sheets(1).Cells(20, 2).Value = "    Hi   Hi   "
    ThisWorkbook.Sheets(2).Cells(20, 3).Value = "    XYZ   XYZ   "
    
    For Each WS In ThisWorkbook.Worksheets
        For Each aCell In WS.UsedRange.SpecialCells(xlCellTypeConstants)
            aCell = WorksheetFunction.Trim(aCell)
        Next aCell
    Next
    
    Application.ScreenUpdating = True
    
    
    End Sub

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: How to skip empty sheet?

    Hi VAer,

    Here is one option:

    Sub removeextraspace()
    
    Dim WS As Worksheet
    Dim WB As Workbook
    Dim aCell As Range
    
    Application.ScreenUpdating = False
    
    ThisWorkbook.Sheets(1).Cells(20, 2).Value = "    Hi   Hi   "
    ThisWorkbook.Sheets(2).Cells(20, 3).Value = "    XYZ   XYZ   "
    
    For Each WS In ThisWorkbook.Worksheets
        If Not IsEmpty(WS.UsedRange) Then
            MsgBox WS.UsedRange
            For Each aCell In WS.UsedRange.SpecialCells(xlCellTypeConstants)
                aCell = WorksheetFunction.Trim(aCell)
            Next aCell
        End If
    Next
    
    Application.ScreenUpdating = True
    
    
    End Sub
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor VAer's Avatar
    Join Date
    09-10-2016
    Location
    USA
    MS-Off Ver
    Office 365
    Posts
    803

    Re: How to skip empty sheet?

    [QUOTE=Arkadi[/QUOTE]

    Thanks. I also found the code online: If Application.WorksheetFunction.CountA(WS.Cells) > 0 Then

+ 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. [SOLVED] skip any row with an empty cell
    By mokht in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 09-18-2016, 08:38 PM
  2. [SOLVED] How to skip an empty cell in a column?
    By excelkann in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-19-2016, 12:20 PM
  3. Skip line if cell is empty
    By Krist2 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-03-2015, 09:56 AM
  4. Skip empty cell in formula
    By Jeebos in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 07-01-2014, 03:00 PM
  5. Skip to empty row or Creating a log
    By vikshrasss in forum Excel General
    Replies: 1
    Last Post: 01-25-2013, 11:24 AM
  6. Skip to empty row or Creating a log
    By vikshrasss in forum Excel - New Users/Basics
    Replies: 0
    Last Post: 01-23-2013, 09:53 AM
  7. [SOLVED] skip empty sheets
    By Rob in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-06-2005, 10:06 AM

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