ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Multiple IF statements (https://www.excelbanter.com/excel-programming/347621-multiple-if-statements.html)

Matt

Multiple IF statements
 
I have the following

Set iSect = Application.Intersect(Range("UserName"), Target)
If Not iSect Is Nothing Then
For Each tCell In iSect
If tCell.Value < UCase(tCell.Value) Then
tCell.Value = UCase(tCell.Value)

If Len(Trim(tCell.Value)) = 0 Then tCell.Value = "Enter Name"
If Len(Trim(tCell.Value)) = 0 Then Call DefaultValueMsg
End If

Next
End If

How can I correct this so the last two IF statements work. The first
portion works fine.

bpeltzer

Multiple IF statements
 
I'll assume that by 'work', you mean that both 'then' clauses get executed.
As it's set up, when you put "Enter Name" in the cell, you guarantee that the
next test (length = 0) will fail. Set it so that you only make the decision
once, executing both statements if the length is 0:
If Len(Trim(tCell.Value)) = 0 Then
tCell.Value = "Enter Name"
Call DefaultValueMsg
End iF
(That all replaces the two lines that begin if len(trim(tcell.value)) = 0).

"Matt" wrote:

I have the following

Set iSect = Application.Intersect(Range("UserName"), Target)
If Not iSect Is Nothing Then
For Each tCell In iSect
If tCell.Value < UCase(tCell.Value) Then
tCell.Value = UCase(tCell.Value)

If Len(Trim(tCell.Value)) = 0 Then tCell.Value = "Enter Name"
If Len(Trim(tCell.Value)) = 0 Then Call DefaultValueMsg
End If

Next
End If

How can I correct this so the last two IF statements work. The first
portion works fine.



All times are GMT +1. The time now is 01:13 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com