ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Showing rows containing text (https://www.excelbanter.com/excel-programming/380218-showing-rows-containing-text.html)

Billy B

Showing rows containing text
 
I have figured out how to search rows in a worksheet and display only rows
that contain text that matches the users input (the code is below). What I am
not able to figure out is how to display rows with text containing text that
the user inputs into the inputbox. I tried putting the * in front of the text
in the inputbox but that does not work. Any help would be greatly appreciated.

Dim r As Range
ActiveWorkbook.Worksheets(1).Range("A1").Select
v = UCase(Application.InputBox("Enter Course Number:", "Course", Type:=2))
Rows.Range("Courses").EntireRow.Hidden = True

For Each r In ActiveSheet.UsedRange
If InStr(r.Value, v) < 0 Then
Rows(r.Row).EntireRow.Hidden = False
End If
Next
Cells(1, 1).Select
End Sub

Martin Fishlock

Showing rows containing text
 
Billy,

I'm not quite sure what it is you are trying to do.

Do you want a combo/list box for the user to select the course?

If so it may be easier to use auto filter on the table as the user can pull
that down.

Please explain a little more.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Billy B" wrote:

I have figured out how to search rows in a worksheet and display only rows
that contain text that matches the users input (the code is below). What I am
not able to figure out is how to display rows with text containing text that
the user inputs into the inputbox. I tried putting the * in front of the text
in the inputbox but that does not work. Any help would be greatly appreciated.

Dim r As Range
ActiveWorkbook.Worksheets(1).Range("A1").Select
v = UCase(Application.InputBox("Enter Course Number:", "Course", Type:=2))
Rows.Range("Courses").EntireRow.Hidden = True

For Each r In ActiveSheet.UsedRange
If InStr(r.Value, v) < 0 Then
Rows(r.Row).EntireRow.Hidden = False
End If
Next
Cells(1, 1).Select
End Sub


Billy B

Showing rows containing text
 
The user inputs a word into an inputbox, all rows are hidden then the loop
unhides those rows that contain the word typed in the inputbox. Hope that
helps.

"Martin Fishlock" wrote:

Billy,

I'm not quite sure what it is you are trying to do.

Do you want a combo/list box for the user to select the course?

If so it may be easier to use auto filter on the table as the user can pull
that down.

Please explain a little more.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Billy B" wrote:

I have figured out how to search rows in a worksheet and display only rows
that contain text that matches the users input (the code is below). What I am
not able to figure out is how to display rows with text containing text that
the user inputs into the inputbox. I tried putting the * in front of the text
in the inputbox but that does not work. Any help would be greatly appreciated.

Dim r As Range
ActiveWorkbook.Worksheets(1).Range("A1").Select
v = UCase(Application.InputBox("Enter Course Number:", "Course", Type:=2))
Rows.Range("Courses").EntireRow.Hidden = True

For Each r In ActiveSheet.UsedRange
If InStr(r.Value, v) < 0 Then
Rows(r.Row).EntireRow.Hidden = False
End If
Next
Cells(1, 1).Select
End Sub


Martin Fishlock

Showing rows containing text
 
Billy,

I was really asking about the * and the input text.

But your macro seems to work for me. The only area that may be a problem is
your range definition of courses.

You hide the range course but check theused range.

I don't undestand where the problem is.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Billy B" wrote:

The user inputs a word into an inputbox, all rows are hidden then the loop
unhides those rows that contain the word typed in the inputbox. Hope that
helps.

"Martin Fishlock" wrote:

Billy,

I'm not quite sure what it is you are trying to do.

Do you want a combo/list box for the user to select the course?

If so it may be easier to use auto filter on the table as the user can pull
that down.

Please explain a little more.

--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Billy B" wrote:

I have figured out how to search rows in a worksheet and display only rows
that contain text that matches the users input (the code is below). What I am
not able to figure out is how to display rows with text containing text that
the user inputs into the inputbox. I tried putting the * in front of the text
in the inputbox but that does not work. Any help would be greatly appreciated.

Dim r As Range
ActiveWorkbook.Worksheets(1).Range("A1").Select
v = UCase(Application.InputBox("Enter Course Number:", "Course", Type:=2))
Rows.Range("Courses").EntireRow.Hidden = True

For Each r In ActiveSheet.UsedRange
If InStr(r.Value, v) < 0 Then
Rows(r.Row).EntireRow.Hidden = False
End If
Next
Cells(1, 1).Select
End Sub



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

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