VBA Len FUNCTION

LEN

In excel vba we use LEN Function to count number of character is used in any supplied string and we store it at supplied variable.

 

Excel vba में हम Len Function का प्रयोग किसी String या Cell में मौजूद value का length जानने के लिए करते है कि यहाँ कितने character use हुआ है और उसे हम एक variable पर store करते है.


Example 1:-

Sub LEN1()
Dim LN As Integer
LN = Len(“COMPUTER”)
End Sub

In this macro I have declared LN as integer(Variable) and assigning the value on LN, which we are getting the length of COMPUTER, which is 8. And we can use LN in whole macro.

इस macro में हमने LN नाम का Integer Variable declare किया है. जिस पर हम COMPUTER word में जितना करैक्टर use हुआ है वो LN पर स्टोर हो जायेगा. जो कि 8 है और उसे हम पुरे Macro मैं कहीं भी use कर सकते है.


 

Example 2:-

Sub LEN2()
MsgBox Len(Range(“A1”).Value)
End Sub

In this macro message box will display number of character used in A1 Cell, which is 5

इस Macro मैं Excel sheet पर A1 Cell में जो value है, उसमे कितना character use हुआ है वो Message Box में display करेगा, जो कि ५ है.


 

 

Example 3:-

Sub LEN3()
For Each cell In Range(“a1:a4”)
LN = Len(cell.Value)
x = x + LN
Next cell
MsgBox x
End Sub

In this macro we have some value at excel sheet from range A1 TO A4. I want sum of len of all cell value. For this I have used For each cell loop, in this loop macro will go to each cell and count the len of that cell value and adding them one by one in X variable at last message box shows x value as sum of total number of len of A1 cell To A4 Cell.

 

हमारे पास एक्सेल शीट पर A1 से A4 तक कुछ value है. मैं सारे cell में कितना character use हुआ है, वो message box में display करना चाहता हूँ. इसके लिए हमें for each loop का प्रयोग करना होगा, इस loop में cursor सारे cell में जायेगा और उसका Len Count कर के, उसे एक एक कर X variable में जोड़ता जायेगा और अंत में message box X के वैल्यू को display देगा, जो सारे cell का Len का जोड़ होगा.

Click Here to Download Excel File