Excel VBA HELP ! > hide & filter columns based on entries in a range on another sheet

AidanKing

New Member
Joined
Feb 2, 2016
Messages
4
Hi All, I'm fairly new to coding (about 1.5 yrs basic coding) and i am stuck with this issue: I have a range "Countries" C13:C33 (in a sheet (sheet called "Selection") where a user can type a pre-determined list of countries "Austria, Spain, France etc etc. Once entered, I need the code to jump to another sheet (called "Company information (1)") and hide all columns that do not contain these countries. The country will be present in the column name, the range of columns is "D2:AU" and can have countries or blanks as column names. Once that step is completed I then need the script to filter the visible row that has the most records for "non-blanks" or "Yes" (all rows will have either "blanks" or "yes" entries only.
I have 3 or 4 versions of the code but this is the most recent. I don't know if it is even much help?

Any help is much apreciated as i've be at this now for hours (& 3 or 4 different iterations/approaches to no avail)

(I currently have the code linked to a command button but this is not critical)

Here is the code:
Private Sub CommandButton3_Click()

Dim rCrit1 As Range, rCrit2 As Range, rRng1 As Range, rRng2 As Range


With Application
.EnableEvents = False
.ScreenUpdating = False


End With
Set rCrit1 = Range("C13:C43")
'Set rCrit2 = Range("C13:C43")


Set rRng1 = Sheets("Selection").Range("C13:C43")
Set rRng2 = Sheets("Company information (1)").Range("A:AU")


With rRng2
For Each Record In rRng1
rCrit1 = rRng2 Then
Rows("rRng2").EntireRow.Hidden = false Criterial:= rRng1.Value, true
.AutoFilter field:=1, Criteria1:="yes"
Application.EnableEvents = True
End Sub
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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