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 / May 2008

Tip: Looking for answers? Try searching our database.

>= Greater than or Equal to Not working

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Corey .... - 22 May 2008 06:48 GMT
I have a short code to search column C ina sheet for Numerical values as
below:

Private Sub TextBox1_Change()
If IsNumeric(TextBox1.Value) = False Then TextBox1.Value = ""
If TextBox1.Value <> "" Then
ListBox1.Clear
ListBox2.Clear
ListBox3.Clear
ListBox1.AddItem "Solid Woven"
ListBox1.AddItem "Rubber Ply"
ListBox1.AddItem "Steel Cord"
Dim LastCell As Long
Dim myrow As Long
LastCell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row
With ActiveWorkbook.Worksheets("InspectionData")
.Select
   For myrow = 1 To LastCell
   If .Cells(myrow, 3) <> "" And .Cells(myrow, 3).Value <> 0 Then
       If IsNumeric(.Cells(myrow, 3)) = True Then
       ListBox3.AddItem Cells(myrow, 3)
       End If
   End If
   Next
End With

It works great, but i need to add a condition so that ONLY values (>=) to
the value in Textbox1 is shown in Listbox3.
But as below, when i add that section of code highlighted, i get NO values
at all.

If IsNumeric(TextBox1.Value) = False Then TextBox1.Value = ""
If TextBox1.Value <> "" Then
ListBox1.Clear
ListBox2.Clear
ListBox3.Clear
ListBox1.AddItem "Solid Woven"
ListBox1.AddItem "Rubber Ply"
ListBox1.AddItem "Steel Cord"
Dim LastCell As Long
Dim myrow As Long
LastCell = Worksheets("InspectionData").Cells(Rows.Count, "C").End(xlUp).Row
With ActiveWorkbook.Worksheets("InspectionData")
.Select
   For myrow = 1 To LastCell
   If .Cells(myrow, 3) <> "" And .Cells(myrow, 3).Value <> 0 Then
       If IsNumeric(.Cells(myrow, 3)) = True And .Cells(myrow, 3).Value >=
TextBox1.Value Then ' <==== THIS BIT HERE
       ListBox3.AddItem Cells(myrow, 3)
       End If
   End If
   Next
End With
End If
End Sub

How can i sucessfully add that condition so it WILL work?

Corey....
Mike H - 22 May 2008 08:49 GMT
Hi,

Textboxes return text so you must look at val(Textbo....etc.
Try this

Private Sub TextBox1_Change()
If IsNumeric(TextBox1.Value) = False Then TextBox1.Value = ""
If TextBox1.Value <> "" Then
   ListBox1.Clear
   ListBox2.Clear
   ListBox3.Clear
   ListBox1.AddItem "Solid Woven"
   ListBox1.AddItem "Rubber Ply"
   ListBox1.AddItem "Steel Cord"
   Dim LastCell As Long
   Dim myrow As Long
   Stop
   LastCell = Worksheets("InspectionData").Cells(Rows.Count,
"C").End(xlUp).Row
   With ActiveWorkbook.Worksheets("InspectionData")
   For myrow = 1 To LastCell
   If .Cells(myrow, 3) <> "" And .Cells(myrow, 3).Value <> 0 Then
       If IsNumeric(.Cells(myrow, 3)) And .Cells(myrow, 3).Value >=
Val(TextBox1.Value) Then ' <==== THIS BIT HERE
       ListBox3.AddItem Cells(myrow, 3)
       End If
   End If
   Next
End With
End If
End Sub

Mike

> I have a short code to search column C ina sheet for Numerical values as
> below:
[quoted text clipped - 55 lines]
>
> Corey....
ctm - 22 May 2008 11:50 GMT
I will have a look at it when back on Monday.
Thank you for your reply Mike.
I am confident that was the error in the code.

Corey....
> Hi,
>
[quoted text clipped - 93 lines]
>>
>> Corey....
 
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.