Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Problem in using If Condition in.csv in blank cell

0
If wsh3.Range("A2") = "" Then

Actually i writed the code but it is not working perfect for me & So plz help in solving this Problem

Hi Sir/Mam

My condition-If wsh3.Range A2 cell does not have a single  Alphabets in A2 cell Then (A2 cell may have Numbers Or Special Characters Or anything in it But we have to look for Alphabets in A2 cell  ) 

Plz help me in making the perfect line for my condition

Answer
Discuss

Answers

0
Selected Answer

Rider

If you want to detect whene A2 of your .csv does NOT contain any alphabetic characters, use:

If Not wsh3.Range("A2").Value Like "*[a-zA-Z]*" Then

This would be TRUE for "123" in A2 of your .csv file or an empty cell.but FALSE for "Excel123".

Omit the Not is you want to detect when it DOES contain alphabetic characters (or work with the Else statement after the test above).

Note that you can detect empty cells using the VBA's LEN  function. That returns the number of characters in a cell e.g. "123" would give 3 but any empty cell gives 0, even in a .csv file (where an "empty" may contain special characters). Use:

If Len(wsh3.Range("A2").Value) = 0 Then

Hope this helps.

Discuss

Discussion

Thnx Sir for Showing interest in helping me in solving this problem
I already tried this also but i have  a problem with it

Actually
A2 cell will have anything except Alphabets or Numericals in A2 cell
Or
A2 cell will have anything with Alphabets Or Alphabets with anything

Anything may be comma Or Special characters or may be anything

But what we have to check is
If wsh3.Range("A2").Value <> doesn't have Alphabets with anything Or anything with Alphabets Then


A2cell is of. Csv file
rider1234 (rep: 10) Sep 9, '22 at 2:17 pm
I will try to look again tomorrow (my time) 
John_Ru (rep: 3992) Sep 9, '22 at 2:53 pm
I'm still not clear on your question but please see my revised answer.

If that does not help, please edit your question and use the Add Files... button to upload a representative Excel file (without any personal data) to show your existing macro and examples of the cells you want to be TRUE and FALSE when tested by the If statement. Note that you can NOT upload a .csv file with your question (but could embed one - as an icon- inside a .xlsm file).
John_Ru (rep: 3992) Sep 10, '22 at 3:18 am
I made my Condition very Simple So Just see the Requirement again Sir & Plz help me in solving the same
rider1234 (rep: 10) Sep 12, '22 at 12:08 am
Rider.please see my revised answer. If that doesn't suit, please attach a file like I asked above.
John_Ru (rep: 3992) Sep 12, '22 at 2:47 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login