Adding an 'OR' to the VBA Statement

mrbeanyuk

Board Regular
Joined
Nov 30, 2005
Messages
214
Office Version
  1. 365
Platform
  1. Windows
Good morning all. I have a working macro below that filters column E according to the username of a person.

I would however like to add a second criteria into the mix that effectively says to filter by column E or F. For example, it may be that my username is in Column F but not E, or vice versa, and then filter accordingly.

Is that too tricky to achieve?

Thanks in advance!

Code:
Sub Users_Fullname()
 
Dim objInfo
Dim strLDAP
Dim strFullName
Dim LR
    
Set objInfo = CreateObject("ADSystemInfo")
strLDAP = objInfo.UserName
Set objInfo = Nothing
strFullName = GetUserName(strLDAP)
  
'MsgBox "Full name of User is " & strFullName  (step to test)

'filter
With Sheets("All KPIs - all columns")
    LR = .Cells(.Rows.Count, 2).End(xlUp).Row
    .Cells(2, 5).AutoFilter Field:=5, Criteria1:=strFullName
End With

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
use ADVANCED FILTER
or
create a new column with a combination of E and F
 
Last edited:
Upvote 0
I’m not quite sure how to apply auto filter in VBA. I’d welcome some guidance please!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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