Results 1 to 5 of 5

Thread: Save Worksheets As Seperate Workbooks Based On Conditions

  1. #1
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0

    Save Worksheets As Seperate Workbooks Based On Conditions

    Hi Everyone,

    Please help me again in my project. I have to save a specific worksheet when a value is seen in a specific range.

    Here's my code.

    Code:
    
    Sub export()
    
    Dim keyword As String
    Sheets("INSTRUCTIONS").Activate
    keyword = Range("O24").Value
    
    If keyword = "AMERICAS" Then
    
        Sheets("CLASSIFIED-americas").Copy
         With ActiveWorkbook
         '.Title = "Classified"
         .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls"), xls
            '.Close True
    
        If keyword = "RRRS" Then
            Sheets("CLASSIFIED-RRRS").Copy
               With ActiveWorkbook
               '   .Title = "Classified"
              .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls"), xls
                 ' .Close True
    
            If keyword = "RRR" Then
                Sheets("CLASSIFIED-RRR").Copy
                 With ActiveWorkbook
                 '   .Title = "Classified"
                .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls"), xls
                   ' .Close True
    
    End If
        End If
            End If
                End If
            
    
         
        Application.DisplayAlerts = True
       
      
    End With
    End Sub
    Thank you for those who will help me.

  2. #2
    Member
    Join Date
    Jun 2013
    Posts
    93
    Rep Power
    12
    attach please a sample file for testing

  3. #3
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Untested.

    Code:
    Option Explicit
    
    Sub Export()
    
        Dim Keyword As String
        
        Keyword = UCase$(Worksheets("INSTRUCTIONS").Range("O24").Value)
        
        Application.DisplayAlerts = False
        
        Select Case Keyword
            Case "AMERICAS"
                Sheets("CLASSIFIED-americas").Copy
                With ActiveWorkbook
                    '.Title = "Classified"
                    .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls", "xls")
                    '.Close True
                End With
            
            Case "RRRS"
                Sheets("CLASSIFIED-RRRS").Copy
                With ActiveWorkbook
                     '   .Title = "Classified"
                    .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls", "xls")
                    ' .Close True
                End With
            
            Case "RRR"
                Sheets("CLASSIFIED-RRR").Copy
                With ActiveWorkbook
                    '   .Title = "Classified"
                    .SaveAs Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls", "xls")
                   ' .Close True
                End With
        End Select
        Application.DisplayAlerts = True
    
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  4. #4
    Banned
    Join Date
    May 2013
    Posts
    17
    Rep Power
    0
    It seems that the
    Code:
    .SaveAs Application.GetSaveAsFilename("FILENAME HERE", "Excel 97-2003 Workbook (*.xls), *.xls", "xls")
    is having an error while compiling. Please help. It has an error of Method SaveAs of the Workbook as Failed or the Runtime Error 1004

    Thanks!

  5. #5
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,123
    Rep Power
    10
    Hi

    Try this

    Code:
    Option Explicit
    
    Sub Export()
    
        Dim Keyword As String
        Dim FName   As Variant
        
        Keyword = UCase$(Worksheets("INSTRUCTIONS").Range("O24").Value)
        
        Select Case Keyword
            Case "AMERICAS"
                Sheets("CLASSIFIED-americas").Copy
                FName = Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls")
            Case "RRRS"
                Sheets("CLASSIFIED-RRRS").Copy
                FName = Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls")
            Case "RRR"
                Sheets("CLASSIFIED-RRR").Copy
                FName = Application.GetSaveAsFilename("CLASSIFIED", "Excel 97-2003 Workbook (*.xls), *.xls")
        End Select
        
        If Not IsEmpty(FName) Then
            Application.DisplayAlerts = False
            ActiveWorkbook.SaveAs FName
            Application.DisplayAlerts = True
        End If
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

Similar Threads

  1. Delete Rows Based on Conditions
    By AbiG2009 in forum Excel Help
    Replies: 6
    Last Post: 12-26-2018, 01:24 PM
  2. Save Worksheets As New File To Specific Folder
    By k0st4din in forum Excel Help
    Replies: 18
    Last Post: 06-08-2013, 04:24 PM
  3. Replies: 4
    Last Post: 03-22-2013, 01:47 PM
  4. Save each Worksheets as Macro disabled workbooks
    By nickface in forum Excel Help
    Replies: 1
    Last Post: 01-28-2013, 07:47 AM
  5. split data into multiple workbooks with 3 conditions.
    By malaionfun in forum Excel Help
    Replies: 5
    Last Post: 05-11-2012, 11:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •