Help with Multifunctional Button

vinylspin02

New Member
Joined
Jul 13, 2011
Messages
1
I'm currently working on an excel file for work and have my current code for a button below. I have it doing a couple of things: SaveAs once a button is pushed with a confirmation MSG box, eliminating the pop-up box that ask about recalculting the cells, and I just have it saving under a certain name in a certain location. I also have it hiding the sheet once the button is pushed.

I'd like to be able to only have it save if certain cells are filled out (A2, B6, C10) for example. I'd also want to displace a error message if they aren't and not allow the SaveAs to happen. If I can do this, I can eliminate the confirmation msg box all together. I'm having a good bit of trouble with this as I'm brand new to this and have just pieced together the code below. Thanks for any and all help.





Sub Saveasfilename2()
Dim folder, cvalue, cvalue1, cvalue2, NewFname As String

folder = "C:\Users\James Kimbrell\Documents\"
cvalue = Sheets(3).Range("G4").Value
cvalue1 = Sheets(3).Range("D58").Value
cvalue2 = Sheets(3).Range("G58").Value
Answer = MsgBox("Do you want to continue ?", _
vbOKCancel, "Form Submission Confirmation")
If Answer = vbCancel Then Exit Sub ' the macro ends if the user selects the CANCEL-button
If Answer = vbOK Then NewFname = cvalue & "_" & "Rxn_" & cvalue1 & "-" & cvalue2 & "_" & Format(Date, "mmddyy") & ".xls"
Application.DisplayAlerts = False
Dim colSheetsToHide As Collection
Dim wks As Worksheet
' collection of sheets to hide when workbook is saved
Set colSheetsToHide = New Collection
With colSheetsToHide
.Add Sheets("Poly 2")
End With
' hide worksheets in collection
For Each wks In colSheetsToHide
wks.Visible = False
Next wks

ActiveWorkbook.SaveAs Filename:=NewFname, FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False

Application.DisplayAlerts = True


End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Forum statistics

Threads
1,224,602
Messages
6,179,843
Members
452,948
Latest member
UsmanAli786

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