简体   繁体   中英

VBA sheet to new workbook if specific cell populated

I have a macro built that copies a single sheet from my workbook to a new workbook and saves the new workbook in a specific location. I have built out my source file and have 3 sheets (of 6) which possibly need to be added to the new saved file.

I would like save sheet 4 (the original) sheet to a new file, then look at sheet 2 and if c2 has a specific result, move the sheet to the new file, then look at sheet 17 and if c2 has a specific result, move the sheet to the new file.

And save.

My struggle is on referencing a specific cell to call the action.

My struggle is on referencing a specific cell to call the action.

you can use a button and assigned your created macro on it just to trigger the action.

@urdearboy

Sub Cleanup()
'
' Cleanup Macro
'
' Keyboard Shortcut: Ctrl+e
'
'This is some clean up stuff on a specific tab, somewhere after this I need to add the check of a specific cell and pull the full sheet. 
    Application.ScreenUpdating = False

    'Get path for desktop of user PC
    Path = Environ("USERPROFILE") & "\Desktop"
    Sheets("Uploader").Cells.Copy

    'Create new workbook and past copied data in new workbook & save to desktop
    Workbooks.Add (xlWBATWorksheet)
    ActiveWorkbook.ActiveSheet.Paste
    ActiveWorkbook.ActiveSheet.Name = "Upload"
    x = Weekday(Date, vbSaturday)
Select Case x
    Case 1
        x = 2
    Case 2
        x = 3
    Case Else
    x = 1
End Select

    ActiveWorkbook.SaveAs Filename:=Path & "\" & "Upload " & Format(CStr(Date - x), "mmddyyyy") & ".xlsx"

        ' start email
    Dim Outlook As Object, EMail As Object

Set Outlook = CreateObject("Outlook.Application")

Set EMail = Outlook.CreateItem(0)

With EMail
    .To = "1"
    .CC = "2"
    .BCC = ""
    .Subject = "File is Ready"
    .Body = "Isn't Automation Amazing!?"
    .Attachments.Add ActiveWorkbook.FullName ' To add active Workbook as attachment
    '.Attachments.Add "" ' To add other files just use path, Excel files, pictures, documents pdf's ect.
    .Display   'or use .Send to skip preview
End With


Set EMail = Nothing

Set Outlook = Nothing
'end email
    ActiveWorkbook.Close savechanges:=True

Application.ScreenUpdating = True


    ActiveWorkbook.Close savechanges:=False

    End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM