Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Looping through a specific column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlee - 21 Apr 2007 00:06 GMT
Hi,

I want to be able to loop through column B and search for a value that is
stored in a text box (txtCriteria1) on my userform.  If the value is found in
column B, display  message saying 'exists', else, display a message that says
'does not exist'.

Can anyone help?  

Signature

Carlee

Norman Jones - 21 Apr 2007 00:50 GMT
Hi Carlee,

One way:

'=============>>
Private Sub CommandButton1_Click()
   Dim WB As Workbook
   Dim SH As Worksheet
   Dim Rng As Range
   Dim sStr As String
   Dim msg As String

   Set WB = ThisWorkbook
   Set SH = WB.Sheets("Sheet1")
   Set Rng = SH.Columns("B:B")
   sStr = Me.txtCriteria1.Value

   If Application.CountIf(Rng, sStr) Then
       msg = sStr & " found"
   Else
       msg = sStr & " not found"
   End If

   MsgBox Prompt:=msg

End Sub
'<<=============

---
Regards,
Norman

> Hi,
>
[quoted text clipped - 6 lines]
>
> Can anyone help?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.