VBA create form and save file of specific sheets

missbb9413

New Member
Joined
May 6, 2017
Messages
1
I have a VBA code to create staff form. there are two problems need to be solved.
Q1 : after creating sheets, the sheets will be saved as file. I only want to save the sheet(7) to sheets.count ? (i.e. sheet (1) to sheet (6) is not required to save file. but below code will save all sheets. Please help!

Sub copusheettofile1()


For Each sh In Worksheets

sh.Copy

ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "" & sh.Name & ".xlsx"
Workbooks(sh.Name & ".xlsx").Close True

Next

End Sub




Q2 : I have included Application.ScreenUpdating = False and Application.DisplayAlerts = False to below code, but I always see some screenupdating image , is there anything wrong ?


Sub copytosheetok02()
'step select dept -> create appraisal form based on sheet result


Application.ScreenUpdating = False
Application.DisplayAlerts = False

With Sheets("list").Activate


Dim yn As Integer
Dim formname As String
Dim dept As String
Dim DDate As Long




yn = MsgBox(prompt:="filter is Dept press YES;filter is join date press NO ", Buttons:=vbYesNo + vbQuestion)
If yn = vbYes Then


On Error Resume Next

dept = Sheets("menu").Range("e9").Value
Sheets("list").Range("a1").AutoFilter Field:=7, Criteria1:=dept
ActiveSheet.UsedRange.Select
Selection.Copy
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "result"
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Sheets("result").Range("b2").Select
ActiveCell.FormulaR1C1 = "=RC[3]&""""&RC[-1]"
Selection.AutoFill Destination:=Range("b2:b" & Range("A" & Rows.Count).End(xlUp).Row)


Else


DDate = Sheets("menu").Range("e13").Value
Sheets("list").Range("a1").AutoFilter Field:=6, Criteria1:=">" & DDate
ActiveSheet.UsedRange.Select
Selection.Copy
Sheets.Add after:=Sheets(Sheets.Count)
Sheets(Sheets.Count).Name = "result"
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
xlNone, SkipBlanks:=False, Transpose:=False
Sheets("result").Range("b2").Select
ActiveCell.FormulaR1C1 = "=RC[3]&""""&RC[-1]"
Selection.AutoFill Destination:=Range("b2:b" & Range("A" & Rows.Count).End(xlUp).Row)

End If


End With


Sheets("menu").Activate


Application.ScreenUpdating = True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top