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
 

Forum statistics

Threads
1,081,727
Messages
5,360,910
Members
400,602
Latest member
newaqua

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top