ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping through a specific column (https://www.excelbanter.com/excel-programming/387869-looping-through-specific-column.html)

Carlee

Looping through a specific column
 
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?


--
Carlee

Norman Jones

Looping through a specific column
 
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


"Carlee" wrote in message
...
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?


--
Carlee





All times are GMT +1. The time now is 12:11 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com