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

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
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,224,837
Messages
6,181,255
Members
453,028
Latest member
letswriteafairytale

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