How to check if a row is a valid column name?

I have a column name (A, B, C, AB, AC ,,) stored in a string variable. My requirement is to get the column number. Before that, I just want to check if the column name is set correctly or not. For example, AD,AC,DF,ER,FC,KL valid there World,kavisuja where World,kavisuja . If I have the correct column name, I can get the following code:

 Range(ColumnChar & 1).Column 

How can I achieve this .. Can someone help me do this .. Thanks in advance ..

+1
vba excel-vba excel
Oct 10 '17 at 6:38
source share
1 answer

This is how I would do it, very similar to the @ YowE3K idea in the comments:

 Option Explicit Public Sub TestMe() Debug.Print isValid("ZZZ") 'False Debug.Print isValid("ZZ") 'True Debug.Print isValid("ABCD") 'False End Sub Public Function isValid(strInput As String) As Boolean On Error GoTo isValid_Error Dim rngSet As Range Set rngSet = Range(strInput & "1") isValid = True On Error GoTo 0 Exit Function isValid_Error: End Function 

The default value of the function is False , therefore, if it is not set to True , the default value is False .

+2
Oct 10 '17 at 8:04 on
source share



All Articles