Else without If

ChrisM92

New Member
Joined
Nov 4, 2020
Messages
21
Office Version
  1. 2019
Platform
  1. Windows
Hi,

When running my code, i keep getting a compile error - Else without if, and it highlights the Else in the middle of the attached. Any ideas why it doesn't want to work? There is definitely an if at the start..
It's part of a larger code that when you click submit on a user form, it puts the data from the "PHE_DateText" box, into a variable cell range based on which BadgeID had been selected.

VBA Code:
If PHE_DateText.Value = "" Then Worksheets("Badge Log").Range("K" & BadgeLocation) = ""
Else
Worksheets("Badge Log").Range("K" & BadgeLocation) = DateValue(PHE_DateText.Value)
End If
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
try
VBA Code:
If PHE_DateText.Value = "" Then
    Worksheets("Badge Log").Range("K" & BadgeLocation) = ""
Else
    Worksheets("Badge Log").Range("K" & BadgeLocation) = DateValue(PHE_DateText.Value)
End If
 
Upvote 0
@ChrisM92

Try.
VBA Code:
If PHE_DateText.Value = "" Then 
Worksheets("Badge Log").Range("K" & BadgeLocation) = ""
Else
Worksheets("Badge Log").Range("K" & BadgeLocation) = DateValue(PHE_DateText.Value)
End If

VBA Code:
If PHE_DateText.Value = "" Then Worksheets("Badge Log").Range("K" & BadgeLocation) = ""
is effectively a single option if and is complete without an End If
Hope that helps.
 
Upvote 0
... and for completeness:
VBA Code:
If PHE_DateText.Value = "" Then Worksheets("Badge Log").Range("K" & BadgeLocation) = "" Else Worksheets("Badge Log").Range("K" & BadgeLocation) = DateValue(PHE_DateText.Value)
... is also an option, less readable though.
 
Upvote 0

Forum statistics

Threads
1,215,487
Messages
6,125,085
Members
449,206
Latest member
ralemanygarcia

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