Notes in Hindi

Understanding Methods vs Properties in Excel VBA in Hindi

Makhanlal Chaturvedi University / BCA / VBA programming

Methods and Properties in Excel VBA Explained in Hindi

Understanding Methods vs Properties in Excel VBA in Hindi

What are Methods in VBA?

VBA में "Method" किसी object पर कोई कार्य (Action) करने का तरीका होता है। जैसे हम Excel में किसी cell को select करते हैं, उसे copy करते हैं, clear करते हैं - यह सभी एक प्रकार के actions हैं और इन्हें VBA में Methods कहा जाता है।

  • Select Method: किसी cell या range को select करने के लिए इस्तेमाल होता है।
  • Copy Method: किसी cell या range की value को copy करने के लिए।
  • Clear Method: किसी cell या range से data हटाने के लिए।

What are Properties in VBA?

"Property" किसी object का गुण (Attribute) होता है। जैसे एक इंसान की उम्र, नाम, लंबाई आदि उसकी properties होती हैं, वैसे ही Excel VBA में किसी cell या range की value, address, font आदि properties होती हैं।

  • Address Property: यह बताती है कि cell या range worksheet में कहाँ स्थित है।
  • Count Property: यह बताती है कि किसी range में कितने cells हैं।
  • Value Property: किसी cell की actual value को set या get करने के लिए।

Methods और Properties में अंतर (Difference between Methods and Properties)

Methods Properties
यह किसी object पर action perform करते हैं यह किसी object की information या विशेषता को दर्शाते हैं
उदाहरण: Range("A1").Select उदाहरण: Range("A1").Address
Result को बदलते हैं Current information return करते हैं या उसे set किया जा सकता है

Commonly Used Methods like Select, Copy, and Clear in Hindi

1. Select Method

Select method का उपयोग Excel VBA में किसी cell या range को active/select करने के लिए किया जाता है।

Range("A1").Select

ऊपर का code A1 cell को select कर देगा।

2. Copy Method

Copy method किसी cell या range की content को copy करने के लिए उपयोग होती है।

Range("A1").Copy Destination:=Range("B1")

यह code A1 की value को B1 में copy कर देगा।

3. Clear Method

Clear method किसी cell या range के content, formatting, या comments को हटाने के लिए होती है।

Range("A1:B2").Clear

यह A1 से B2 तक के सारे data को clear कर देगा।


Useful Properties of Range Object like Address and Count in Hindi

1. Address Property

यह property यह बताती है कि कोई range Excel sheet में कहाँ स्थित है। इसे string के रूप में return किया जाता है।

MsgBox Range("B2").Address

यह message box में "$B$2" return करेगा।

2. Count Property

Count property यह बताती है कि किसी range में कितने cells मौजूद हैं। यह बहुत उपयोगी होती है जब आपको loop चलाना हो या check करना हो कि कितने cells पर काम करना है।

MsgBox Range("A1:A10").Count

यह 10 return करेगा क्योंकि A1 से A10 तक कुल 10 cells हैं।

3. Value Property

इसका उपयोग किसी cell की value को प्राप्त करने या उसमें value set करने के लिए होता है।

Range("A1").Value = "Hello"

यह A1 cell में "Hello" लिख देगा।


Applying .Interior and .Font Properties for Formatting in Hindi

1. Interior Property

Interior property किसी cell के अंदर की background color को set करने के लिए होती है। इसका उपयोग Excel में cell को highlight करने के लिए किया जाता है।

Range("A1").Interior.Color = vbYellow

यह A1 cell की background को पीला कर देगा।

2. Font Property

Font property किसी cell के text का size, color, bold, italic आदि सेट करने के लिए उपयोग होती है।

  • Bold: Text को bold करने के लिए
  • Italic: Text को italic करने के लिए
  • Color: Text color बदलने के लिए
  • Size: Font size set करने के लिए
With Range("A1").Font
  .Bold = True
  .Italic = True
  .Color = vbRed
  .Size = 14
End With

यह code A1 cell के text को bold, italic, लाल रंग और 14 size का बना देगा।

3. Combined Formatting Example

Interior और Font को एक साथ इस्तेमाल करके cell को पूरी तरह से customize किया जा सकता है।

With Range("B2")
  .Value = "Formatted Text"
  .Interior.Color = RGB(200, 200, 255)
  .Font.Name = "Calibri"
  .Font.Size = 12
  .Font.Color = vbBlue
  .Font.Bold = True
End With

यह B2 cell में "Formatted Text" को blue bold font के साथ और हल्के नीले background में दिखाएगा।

FAQs

Methods VBA में actions होते हैं जो किसी object पर काम करते हैं, जैसे Select या Copy करना। Properties object की विशेषताएं होती हैं, जैसे cell का Address या Font size। Methods किसी object पर कार्य करते हैं, जबकि Properties जानकारी return करती हैं या set की जाती हैं।
Select Method का उपयोग किसी cell या range को select करने के लिए किया जाता है। उदाहरण के लिए: Range("A1").Select यह code A1 cell को active बना देगा।
Copy Method किसी cell की value को दूसरे cell में copy करने के लिए उपयोग की जाती है। उदाहरण: Range("A1").Copy Destination:=Range("B1") यह A1 की value को B1 में copy कर देगा।
Address Property किसी range या cell का location return करती है। जैसे Range("C3").Address return करेगा "$C$3" जो बताता है कि cell C3 कहां स्थित है।
Count Property यह बताती है कि किसी range में कितने cells मौजूद हैं। उदाहरण: Range("A1:A5").Count से output मिलेगा 5, क्योंकि A1 से A5 तक 5 cells हैं।
Interior property से cell का background color set किया जाता है, और Font property से text का color, size, style आदि। उदाहरण: Range("A1").Interior.Color = vbYellow और Range("A1").Font.Bold = True से formatting apply होती है।

Please Give Us Feedback