How to make a simple conditional macro ?¿

Joke

Board Regular
Joined
Jan 21, 2004
Messages
171
Yes thanks to this amazing Forum I{m slowly getting into writing Macros but apparently not fast enough. Do need help with this one.

I have a macro that copies some cells in to protected excel database. But now I want to make the macro conditional that is

If there range named CONTROL contains data the saving macro can be executed but if these cells are blank I need an error message and go back to the named cells.

This is how far I that is despite using many example form this Forum i cant get the conditional ...............

I{m sure it is not something difficult, thanks in advance to the expert that can spare some minutes to help me out on this!

Joke

Sub Savedata()
'IF the cells in range D113:F113 (named "control") have a value
other data will be saved in separate file if not a message box will be displayed and empty cells will be selected


Dim ActiveSh As Worksheet
Dim OpenedWb As Workbook
Dim strFname As String
strFname = Range("ubicacion").value
Set ActiveSh = ActiveSheet
Set OpenedWb = Workbooks.Open(Filename:=strFname)
With OpenedWb
.ActiveSheet.Unprotect Password:="x"
.ActiveSheet.Range("A2").EntireRow.Insert
.ActiveSheet.Range("a2:M2").value = ActiveSh.Range("guardar1").value
.ActiveSheet.Protect Password:="x"
.Close True
End With
Application.Goto REference:="comienzo2"

Else
MsgBox "You have to fill the data before saving"
Style = vbOkYes
Application.Goto REference:="control"
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Use counta function in your condition like this:

If WorksheetFunction.CountA(Range("d113:f113")) Then
ActiveWorkbook.SaveAs "c:\my documents\file1.xls"
Else
MsgBox "No Data to Save"
End If
 
Upvote 0

Forum statistics

Threads
1,214,415
Messages
6,119,382
Members
448,889
Latest member
TS_711

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