Notes in Hindi

Using the .Value and .Text Properties in Excel VBA in Hindi

Makhanlal Chaturvedi University / BCA / VBA programming

Using .Value, .Text, .Formula, .Rows, .Columns, and SpecialCells in Excel VBA in Hindi

Using the .Value and .Text Properties in Excel VBA in Hindi

Introduction to .Value and .Text in Excel VBA

Excel VBA में जब हम किसी cell से data पढ़ते हैं या उसमें data डालते हैं, तब हमें कुछ properties की ज़रूरत होती है। सबसे ज़्यादा इस्तेमाल होने वाली दो properties हैं — .Value और .Text। दोनों properties देखने में एक जैसी लगती हैं, लेकिन इनका उपयोग अलग-अलग परिस्थितियों में होता है।

.Value Property क्या होती है?

.Value property किसी cell की असली value को read या write करने के लिए इस्तेमाल की जाती है। इसका मतलब है कि cell में जो वास्तविक data है, वो हमें .Value से मिलेगा।

  • अगर कोई formula लगाया गया है, तो .Value उसका result देगा।
  • अगर कोई plain number या text है, तो वही return होगा।
Dim data As Variant data = Range("A1").Value MsgBox data

ऊपर के code में A1 cell की value को एक variable में store किया गया है और फिर उसे दिखाया गया है।

.Text Property क्या होती है?

.Text property cell में दिखाई जाने वाली formatted value को return करती है। इसका मतलब है कि जो value आपको Excel में visually दिखाई देती है, वही .Text से मिलती है। यह केवल पढ़ने (Read-Only) के लिए होती है।

  • यह formatting के अनुसार value return करती है (जैसे ₹1,000 या 12-06-2025)।
  • इसका उपयोग तब होता है जब हमें display formatting के अनुसार value चाहिए होती है।
Dim displayedText As String displayedText = Range("A1").Text MsgBox displayedText

.Value और .Text में अंतर

Property काम Use Case
.Value असली डेटा देता है Calculation या डेटा प्रोसेसिंग के लिए
.Text फॉर्मेट किया हुआ डेटा दिखाता है User display के लिए

Exploring .Formula and .FormulaR1C1 in VBA Methods in Hindi

Introduction to .Formula and .FormulaR1C1

Excel VBA में हम cells में formula भी डाल सकते हैं। इसके लिए दो main properties होती हैं — .Formula और .FormulaR1C1। दोनों का उपयोग formula लगाने के लिए होता है लेकिन style अलग होता है।

.Formula Property क्या है?

.Formula property A1 style referencing का उपयोग करती है। यह वही तरीका है जैसा हम Excel sheet में manually formula लगाते समय करते हैं।

Range("B1").Formula = "=A1+10"

ऊपर के code में B1 में formula डाला गया है जो A1 की value में 10 जोड़ता है।

.FormulaR1C1 Property क्या है?

.FormulaR1C1 property R1C1 referencing style का उपयोग करती है। इसमें rows और columns को R और C के द्वारा reference किया जाता है।

  • R = Row
  • C = Column
Range("B1").FormulaR1C1 = "=R1C1+10"

इसमें R1C1 का मतलब है Row 1, Column 1 यानी A1 cell।

दोनों में अंतर

Property Referencing Style Use Case
.Formula A1 style (जैसे A1, B2) Simple और ज़्यादातर इस्तेमाल में
.FormulaR1C1 R1C1 style (जैसे R2C3) Dynamic referencing के लिए

Using .Rows and .Columns Properties for Ranges in Hindi

.Rows और .Columns क्या हैं?

जब हम किसी range के अंदर की rows या columns को manipulate करना चाहते हैं, तब हम .Rows और .Columns properties का उपयोग करते हैं।

.Rows Property का उपयोग

  • यह किसी range के अंदर की सभी rows को represent करता है।
  • हम specific row को भी target कर सकते हैं।
Range("A1:C3").Rows(2).Select

यह code दूसरी row (A2:C2) को select करेगा।

.Columns Property का उपयोग

  • यह किसी range के अंदर की सभी columns को represent करता है।
  • Specific column को access किया जा सकता है।
Range("A1:C3").Columns(3).Select

यह code तीसरा column (C1:C3) select करेगा।

इनका Practical उपयोग

  • Multiple row या column को format करने के लिए
  • Data की loop लगाने के लिए

SpecialCells Method in Excel VBA Explained in Hindi

SpecialCells क्या होता है?

SpecialCells Excel VBA का एक powerful method है, जो हमें किसी range के अंदर विशेष प्रकार की cells को target करने देता है, जैसे कि खाली cells (blanks), constants, formulas आदि।

Common Constants

Constant काम
xlCellTypeBlanks सिर्फ खाली cells को select करता है
xlCellTypeConstants वो cells जिनमें manually value डाली गई हो
xlCellTypeFormulas वो cells जिनमें formula हो

उदाहरण

Blank cells को चुनना:

Range("A1:A10").SpecialCells(xlCellTypeBlanks).Select

Formulas वाली cells को चुनना:

Range("A1:C10").SpecialCells(xlCellTypeFormulas).Select

SpecialCells कब उपयोग करें?

  • Blank cells में color भरने के लिए
  • सिर्फ formulas वाली cells को format करने के लिए
  • Constants और formulas को अलग-अलग identify करने के लिए

Handling Errors

यदि आपके दिए हुए range में SpecialCells का match नहीं मिलता तो VBA error देगा। इसलिए इसे Try-Catch block में उपयोग करना चाहिए या error handling लगानी चाहिए।

On Error Resume Next Range("A1:A10").SpecialCells(xlCellTypeBlanks).Select On Error GoTo 0

FAQs

.Value property actual cell की value देती है, जबकि .Text property उस value का formatted version दिखाती है जैसा Excel में दिख रहा होता है। .Text केवल read-only होती है।
.Formula तब उपयोग करें जब आप A1 style referencing जैसे "=A1+B1" का उपयोग करें। .FormulaR1C1 तब उपयोग करें जब dynamic referencing या loop-based referencing की ज़रूरत हो जैसे "=R1C1+R1C2"।
आप .Rows(index) या .Columns(index) का उपयोग करके range की specific row या column को access कर सकते हैं। जैसे: Range("A1:C3").Rows(2).Select।
SpecialCells method Excel में किसी range के विशेष cells (जैसे blank cells, formula cells, constant cells) को filter करने के लिए प्रयोग होता है। यह automation और formatting के लिए बहुत उपयोगी है।
आप इस code से blank cells को select कर सकते हैं: Range("A1:A10").SpecialCells(xlCellTypeBlanks).Select। यह खाली cells को अलग कर देता है।
नहीं, .Text property केवल read-only होती है। अगर आप cell में data लिखना चाहते हैं तो .Value या .Formula का उपयोग करें।

Please Give Us Feedback