Results 1 to 9 of 9

If else, If then statement needed when data doesnt exist ... help

Threaded View

  1. #1
    Registered User
    Join Date
    07-07-2015
    Location
    Wash DC
    MS-Off Ver
    10
    Posts
    57

    If else, If then statement needed when data doesnt exist ... help

    Situation... I have inheirited a fairly involved excel macro and am running into a problem... THis macro imports a number of files as seperate worksheets, then reorganizes the data in the worksheets and copies it to a central sheet and does some calucations... THe problem is that the macro has a section for editing each workstheet... THere is a sample below... Basically, the script runs "Batch1_GETS, Batch2_GETS, and so on till Batch8_GETS, This edits the data on th worksheet and then copies data to another worksheet after the fact (ParaSoft_Data) for additional calculations... IT woks fine, but the problem is that now the number of batches has now started varying. Now alot of the time we only get Batch 1-6, but we still on occation get 8, so I don't want to remove that section of the code in the macro... The problem is that since there is no Batch7/8 worksheet that when it gets to the Batch7_GETS section in the macro, it causes problems.

    Normally, i would a IF NOT EXIST/ GOTO statement... Basically, I would note in the code - that if something didn't exist (ie Batch7/8_GETS worksheets) it would just skip that section and go on... I know that excel has IF/ElSE statements - but I can't get it work... So I figured I would ask... I would think it shouldn't be too difficult, so if anyone if familiar, I would appreciate some help....

    Ultimately, I would prefer to loop the BatchX_GETS statements, so there wasn't a seperate piece for each workbook, but one thing at a time...

    Thansks in advance..


    ' Batch1_GETS
    
        Sheets("Batch1_GETS").Select
        Columns("C:L").Select
        Selection.Delete Shift:=xlToLeft
        Columns("A:B").Select
        ActiveWorkbook.Worksheets("Batch1_GETS").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Batch1_GETS").Sort.SortFields.Add Key:=Range( _
            "B2:B135"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Batch1_GETS").Sort
            .SetRange Range("A1:B135")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Rows("2:90").Select
        Selection.Delete Shift:=xlUp
        Range("A2:B46").Select
        Selection.Copy
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        Sheets("ParaSoft Data").Select
            Range("A3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    
    
    ' Batch2_GETS
    
        Sheets("Batch2_GETS").Select
        Columns("C:L").Select
        Selection.Delete Shift:=xlToLeft
        Columns("A:B").Select
        ActiveWorkbook.Worksheets("Batch2_GETS").Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Batch2_GETS").Sort.SortFields.Add Key:=Range( _
            "B2:B135"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
            xlSortNormal
        With ActiveWorkbook.Worksheets("Batch2_GETS").Sort
            .SetRange Range("A1:B135")
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
        Rows("2:90").Select
        Selection.Delete Shift:=xlUp
        Range("A2:B46").Select
        Selection.Copy
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        ActiveWindow.ScrollWorkbookTabs Sheets:=-1
        Sheets("ParaSoft Data").Select
            Range("F3").Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #3 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 09-02-2015 at 08:07 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Code to update or insert if doesnt exist
    By bosco2 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-26-2015, 03:29 AM
  2. How to add a value to the last blank cell of a column if it doesnt exist there already.
    By yoursamrit2000 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-20-2015, 04:42 AM
  3. [SOLVED] Find Value in all worksheets, if doesnt exist then...
    By bg_enigma1 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-06-2012, 12:30 PM
  4. If named range doesnt exist next k
    By jordan2322 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-13-2012, 12:17 AM
  5. macro to check if a value exist in sheet and add it if it doesnt
    By RetroGun in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-01-2011, 02:35 AM
  6. Delete row if value(array) doesnt exist in column
    By wobaby in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-24-2009, 02:34 AM
  7. find number that doesnt exist among others.
    By TheBean in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-26-2006, 09:28 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