Results 1 to 4 of 4

Skip a step in the Macro if a range has no data

Threaded View

1-Ton Skip a step in the Macro if a... 07-31-2013, 02:33 PM
codeslizer Re: Skip a step in the Macro... 07-31-2013, 05:05 PM
1-Ton Re: Skip a step in the Macro... 08-05-2013, 02:43 PM
1-Ton Re: Skip a step in the Macro... 08-01-2013, 12:18 PM
  1. #1
    Registered User
    Join Date
    07-29-2013
    Location
    Frisco, TX
    MS-Off Ver
    Excel 2007
    Posts
    5

    Skip a step in the Macro if a range has no data

    Good afternoon,

    This is my first post here, but I have relied upon this forum for solutions to several other problems. So, gratitude is due for your indirect help on prior issues. Now hopefully you can help me directly with my current issue.

    I have a spreasheet and macro which takes bulk data, filters it and pastes it into different tabs based on category, and then subtotals that data before copying and pasting all of the subtotals onto another sheet. The problem I am having is that occasionally there is no data within a certain category, so the correponding sheet will be blank (except for headers). When the macro runs, I get a "run-time error '1004'" when it attempts to sub-total the data on the blank sheet. Is there a way to skip this step of the macro if there is no data within a certain sheet/range?

    If it helps, here is the portion of VBA language where it hangs-up:


    Sheets("Outsource AA").Select
        Columns("A:A").Select
        ActiveWorkbook.Worksheets("Outsource AA").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Outsource AA").Sort.SortFields.Add Key:=Range("A1"), _
            SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Outsource AA").Sort
            .SetRange Range("A2:I999")
            .Header = xlNo
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Columns("B:B").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Columns("A:A").Select
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 4), Array(10, 1)), TrailingMinusNumbers:=True
        Range("A1").Select
        ActiveCell.FormulaR1C1 = "Date"
        Columns("A:A").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
            .WrapText = False
            .Orientation = 0
            .AddIndent = False
            .IndentLevel = 0
            .ShrinkToFit = False
            .ReadingOrder = xlContext
            .MergeCells = False
        End With
        Selection.ColumnWidth = 13
        Columns("B:B").Select
        Selection.Delete Shift:=xlToLeft
        Range("D13").Select
        ActiveWindow.SmallScroll Down:=-15
        Columns("A:A").Select
        Selection.Subtotal GroupBy:=1, Function:=xlCount, TotalList:=Array(1), _
            Replace:=True, PageBreaks:=False, SummaryBelowData:=False    
        Range("C13").Select
        Columns("B:B").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
            Columns("A:A").Select
        Selection.TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
            FieldInfo:=Array(Array(0, 2), Array(9, 1)), TrailingMinusNumbers:=True
        Columns("B:B").Select
        Selection.Delete Shift:=xlToLeft
    Last edited by Leith Ross; 07-31-2013 at 02:41 PM. Reason: Added Code tags

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using VBA To Skip Step If There is Nothing In Cell?
    By alulla in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-26-2013, 08:53 AM
  2. [SOLVED] preventing simple zoom macro from running step by step
    By reece1984 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2012, 06:13 AM
  3. Help with Macro, need it to skip a step if that step isn't needed
    By CDNcameron in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-23-2012, 02:34 PM
  4. run macro step by step. excel 2003
    By PBM in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-19-2005, 10:19 AM
  5. [SOLVED] I need step by step instructions to create a macro for 10 imbedde.
    By diana in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 01-30-2005, 10: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