Data-type, case-match and InputBox issue.

kelly mort

Well-known Member
Joined
Apr 10, 2017
Messages
2,169
Office Version
  1. 2016
Platform
  1. Windows
I have this code here and when I call the InputBox only the admin will match. All the others return the else statement. So I used that UCase but still. What is it that I am missing?

Code:
Option Explicit 
Private UName As Variant,  TheAccount As Variant 
Sub ActiveInactive  ()
        TheAccount = Application.InputBox("Enter the Account name","Activate or Deactivate")

With Sheets("Data")
      For Each UName In . [K4:K13] 
             If UName = UCase(TheAccount) Then
                   MsgBox "Account available"
              Else 
                   MsgBox "Account not available"
              End If
        Next
End With 
End Sub

The account names :

Code:
ADMIN
USER 1
USER 2
USER 3
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What about the space(s) ?
Try this :
Code:
Option Explicit
Private UName As Variant, TheAccount As Variant
Sub ActiveInactive()
Dim c%
TheAccount = Application.InputBox("Enter the Account name", "Activate or Deactivate")
For Each UName In Sheets("Data").[K4:K13]
    If Replace(UName, " ", "") = Replace(UCase(TheAccount), " ", "") Then
        MsgBox "Account available"
        c = 1
        Exit For
    End If
Next
If c <> 1 Then MsgBox "Account not available"
End Sub
 
Upvote 0
What about the space(s) ?
Try this :
Code:
Option Explicit
Private UName As Variant, TheAccount As Variant
Sub ActiveInactive()
Dim c%
TheAccount = Application.InputBox("Enter the Account name", "Activate or Deactivate")
For Each UName In Sheets("Data").[K4:K13]
    If Replace(UName, " ", "") = Replace(UCase(TheAccount), " ", "") Then
        MsgBox "Account available"
        c = 1
        Exit For
    End If
Next
If c <> 1 Then MsgBox "Account not available"
End Sub


Great!!!!!


I knew I was messing up with something.

Thanks a lot for the quick fix.
 
Upvote 0

Forum statistics

Threads
1,215,721
Messages
6,126,461
Members
449,315
Latest member
misterzim

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