help with Excel macro

TeunRoos

New Member
Joined
May 6, 2019
Messages
4
Hello all,

I would like someone to try and make me a macro that can display a couple of rows and columns based on a searched variable.

I added a link to an example of a part of the excel document that I am working in. (It is a Google Spreadsheet)

For example, I want to display row 26 up to row 35 when I search for "testb.com".
Or row 16 up to 25 when I search for "testa.com".

If anyone could help me, thanks!!

https://docs.google.com/spreadsheet...P_a5_TpHFwUhN8uNdDxaACRPWzU/edit?usp=sharing​
 

Excel Facts

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
Hi & welcome to MrExcel
Are you going to be running this in Excel, or in GoogleSheets?
 
Last edited:
Upvote 0
Ok, how about
Code:
Sub TeunRoos()
   Dim Srch As String
   Dim Rng As Range
   
   Srch = InputBox("Enter search item")
   If Srch = "" Then Exit Sub
   For Each Rng In Range("A16", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlConstants).Areas
      If Rng.Offset(, 2).Resize(1, 1).Value = Srch Then
         Rows("16:" & Rows.Count).Hidden = True
         Rng.Offset(-1).Resize(Rng.Count + 1).EntireRow.Hidden = False
      End If
   Next Rng
End Sub
 
Upvote 0
Thanks for the help!

It does kind of work the way it's supposed to, but I tried it and now I lost half of my sheet..
 
Upvote 0
I am pretty new when it comes to Excel, but I found out how to fix this.
Now I have another question, now I have to run the macro via a keyboard shortcut after which I can enter the variable I want to search, but is there a way of just entering the variable into a cell?
 
Upvote 0
Which cell will you enter the search into?
 
Upvote 0

Forum statistics

Threads
1,215,268
Messages
6,123,966
Members
449,137
Latest member
yeti1016

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top