2013-02-18 54 views
22

मुझे Excel शीट में सेल्डा मानना ​​होगा। मैं इसे खोजने के लिए इस VBA कोड उपयोग कर रहा था:वीबीए कोड सेल द्वारा एक्सेल कॉलम में कोई मूल्य कैसे खोजें।

Set cell = Cells.Find(What:=celda, After:=ActiveCell, LookIn:= _ 
    xlFormulas, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:= _ 
    xlNext, MatchCase:=False, SearchFormat:=False) 


If cell Is Nothing Then 
    'do it something 

Else 
    'do it another thing 
End If 

समस्या है जब मैं केवल एक एक्सेल कॉलम में मूल्य लगाना होगा। मैं अगले कोड के साथ इसे खोजने:

Columns("B:B").Select 
    Selection.Find(What:="VA22GU1", After:=ActiveCell, LookIn:=xlFormulas, _ 
     LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
     MatchCase:=False, SearchFormat:=False).Activate 

लेकिन मैं कैसे पहले VBA कोड के लिए यह अनुकूल करने के लिए, क्योंकि मैं मूल्य nothing उपयोग करने के लिए पता नहीं है।

+6

http://www.siddharthrout.com/2011/07/14/find-and-findnext-in-excel-vba/ इसके अलावा का उपयोग कर '.Select' इस लिंक http देखें बचने करें: //stackoverflow.com/questions/10714251/excel-macro-avoiding-using-select/10718179#10718179 –

+0

यदि आप बस जानना चाहते हैं कि मूल्य सीमा में कहीं मौजूद है, तो यह त्वरित निष्पादन है (यदि सैकड़ों की जांच हो तो इसके लायक मूल्य) एक एक्सेल सूत्र का उपयोग करने के लिए। यदि उदाहरण के लिए कोल्डा एक संख्या है, तो आप IF मूल्यांकन ("COUNTIF (शीट 1! ए 1: ए 1000," और सेल्डा और ")")> 0 फिर उपयोग कर सकते हैं ... – lessthanideal

उत्तर

32

बस

Columns("B:B").Select 
Set cell = Selection.Find(What:="celda", After:=ActiveCell, LookIn:=xlFormulas, _ 
     LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _ 
     MatchCase:=False, SearchFormat:=False) 

If cell Is Nothing Then 
    'do it something 

Else 
    'do it another thing 
End If 
4

का उपयोग बस पूर्णता के लिए के लिए, आप भी उसी तकनीक का एक्सेल तालिकाओं के साथ ऊपर का उपयोग कर सकते हैं।

नीचे दिए गए उदाहरण में, मैं "tblConfig" नामक एक्सेल टेबल के किसी भी सेल में एक टेक्स्ट देख रहा हूं, जिसे कॉन्फ़िगर नामक शीट में रखा गया है जो सामान्य रूप से छुपाया जाता है। मैं ढूँढें विधि के डिफ़ॉल्ट स्वीकार कर रहा हूँ।

Dim list As ListObject 
Dim config As Worksheet 
Dim cell as Range 


Set config = Sheets("Config") 
Set list = config.ListObjects("tblConfig") 

'search in any cell of the data range of excel table 
Set cell = list.DataBodyRange.Find(searchTerm) 

If cell Is Nothing Then 
    'when information is not found 
Else 
    'when information is found 
End If 
3
Dim strFirstAddress As String 
Dim searchlast As Range 
Dim search As Range 

Set search = ActiveSheet.Range("A1:A100") 
Set searchlast = search.Cells(search.Cells.Count) 

Set rngFindValue = ActiveSheet.Range("A1:A100").Find(Text, searchlast, xlValues) 
If Not rngFindValue Is Nothing Then 
    strFirstAddress = rngFindValue.Address 
    Do 
    Set rngFindValue = search.FindNext(rngFindValue) 
    Loop Until rngFindValue.Address = strFirstAddress