如果已填充特定单元格,则将VBA工作表添加到新工作簿

时间:2019-02-21 15:01:41

标签: excel vba if-statement

我建立了一个宏,该宏将工作表中的一张纸复制到新工作簿中,并将新工作簿保存在特定位置。我已经建立了我的源文件,并且有3张纸(共6张),可能需要将其添加到新保存的文件中。

我想将工作表4(原始)工作表保存到新文件,然后查看工作表2,如果c2有特定结果,请将工作表移动到新文件,然后查看工作表17,如果c2具有工作表具体结果,将工作表移至新文件。

然后保存。

我的工作是在引用特定单元格来调用操作。

2 个答案:

答案 0 :(得分:0)

我的工作是参考特定的单元格来调用操作。

  

您可以使用按钮并在其上分配创建的宏,以触发操作。

答案 1 :(得分:0)

@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