[RESOLVED] Checking the length of the letterin excel
i am checking the legth of the cell has 5 do someting and greater than 5 it displays the message and stops the macro the macro shows here:
but it gives object error code
but i have in cell 4 e has 5 letter
if Len(aSheet.Cells(4,"e",5)) Then
MyScreen.Area(1,10,1,14).Value = aSheet.Cells(4, "e").Value
ElseIf Len(aSheet.Cells(4, "e").value) > 5 Then
MsgBox ("Corp should be 5 letters in Excel sheet ")
Re: Checking the length of the letterin excel
What is the exact error and on what line does it occur?
Re: Checking the length of the letterin excel
Len(aSheet.Cells(4,"e",5))
OBJECT code error
but in excel it is 5 letters only
Re: Checking the length of the letterin excel
Is this what you are trying?
Code:
If Len(Trim(aSheet.Cells(4, 4).Value)) < 5 Then
'your code
ElseIf Len(Trim(aSheet.Cells(4, 4).Value)) > 5 Then
MsgBox ("Corp should be 5 letters in Excel sheet ")
End If
Re: Checking the length of the letterin excel
yes i tried the same thing but = 5
Re: Checking the length of the letterin excel
what is actually trim will do
Re: Checking the length of the letterin excel
trim remove space/s at beginning and end of string
Re: Checking the length of the letterin excel
Quote:
Originally Posted by india123
yes i tried the same thing but = 5
Sorry i don't understand...
Is this what you want?
vb Code:
'if less than 5
If Len(Trim(aSheet.Cells(4, 4).Value)) < 5 Then
'your code
'if greater than 5
ElseIf Len(Trim(aSheet.Cells(4, 4).Value)) > 5 Then
MsgBox ("Corp should be 5 letters in Excel sheet ")
'if equal to 5
ElseIf Len(Trim(aSheet.Cells(4, 4).Value)) = 5 Then
'your code
End If