Run a macro if cell is not empty
Bonjour
I am new to macros... I want that when clicking on a button, the macros only execute if a specified cell is filled. However, my code does not work, it responds "missing an if condition...
How do I do it? Thank you in advance!
Sub crefeuille1()
' crefeuille1 Macro
If Range("C2") = "" Then
Sheets("Revue type").Select
Sheets("Revue type").Copy After:=Sheets(2)
Set MySheet = ActiveSheet
With MySheet
.Name = Worksheets("Trame").Range("e2")
End If
End With
End Sub
Sub crefeuille2()
'
' crefeuille2 Macro
'
If Range("C3") = "" Then
Sheets("Revue type").Select
Sheets("Revue type").Copy After:=Sheets(2)
Set MySheet = ActiveSheet
With MySheet
.Name = Worksheets("Trame").Range("e3")
End If
End With
End Sub
I am new to macros... I want that when clicking on a button, the macros only execute if a specified cell is filled. However, my code does not work, it responds "missing an if condition...
How do I do it? Thank you in advance!
Sub crefeuille1()
' crefeuille1 Macro
If Range("C2") = "" Then
Sheets("Revue type").Select
Sheets("Revue type").Copy After:=Sheets(2)
Set MySheet = ActiveSheet
With MySheet
.Name = Worksheets("Trame").Range("e2")
End If
End With
End Sub
Sub crefeuille2()
'
' crefeuille2 Macro
'
If Range("C3") = "" Then
Sheets("Revue type").Select
Sheets("Revue type").Copy After:=Sheets(2)
Set MySheet = ActiveSheet
With MySheet
.Name = Worksheets("Trame").Range("e3")
End If
End With
End Sub
3 answers
-
ContributorHello,
If you test C2 apparently empty, you write a formula in a corner of the sheet:
=isblank(C2), if it returns "false" <=> C2 contains a space
hence your remark:
"a space is added at the end of the sheet name"
Your concern is therefore to find out why there is a space in C2 (is C2 a formula? if so, check the precedents)