Is there such a thing as a wild card in vba ?

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,225
Office Version
  1. 2007
Platform
  1. Windows
Hi,
Im using the code below.
I have highlighted two pieces of code.
Red is what the code is to ignor OR I will then see an error message & when i debug i see the code highlighted in Blue selected.

So in the code of what to ignore is next years date of which is 2022

So next year i will start to enter the year 2023 BUT will i remember where etc in the code i need to edit.
So as per title Is there such a thing as a wild card of which i can use so the code justs ignores it ?
Example **2022** or **2023** meaning whatever is between the ** ** is ignored

Thanks

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Dim myStartCol As String
    Dim myEndCol As String
    Dim myStartRow As Long
    Dim myLastRow As Long
    Dim myRange As Range

    If Target.Cells.Count > 1 Then Exit Sub
    If Target.Value = "NEVER" Or Target.Value = "TBA" Or Target.Value = "2022" Then Exit Sub
    Application.ScreenUpdating = False
    
    myStartCol = "A"
    myEndCol = "K"

    myStartRow = 7
    
    myLastRow = Cells(Rows.Count, myStartCol).End(xlUp).Row
    
    Set myRange = Range(Cells(myStartRow, myStartCol), Cells(myLastRow, myEndCol))
    
    If Intersect(Target, myRange) Is Nothing Then Exit Sub
    
    With Target
        .Worksheet.Cells.FormatConditions.Delete
        .FormatConditions.Add xlExpression, , True
        .FormatConditions(1).Interior.Color = vbWhite
    End With
    
    With Sheet7.DTPicker1
    .Height = 40
    .Width = 40
    If Not Intersect(Target, Range("G7:H40")) Is Nothing Then
      .Visible = True
      .Top = Target.Top
      .Left = Target.Offset(0, 1).Left
      .LinkedCell = Target.ADDRESS
    Else
      .Visible = False
    End If
  End With
      
End Sub
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Perhaps something like this ...
Rich (BB code):
    If Target.Value = "NEVER" Or Target.Value = "TBA" Or Target.Value Like "*2022*" Then Exit Sub
 
Upvote 0
If you will always want to ignore a future date year in the current millennium, maybe:
VBA Code:
    If Target.Value = "NEVER" Or Target.Value = "TBA" Or Target.Value Like "*2###*" Then Exit Sub
 
Upvote 0
Hi,
Maybe I didn’t explain correctly.
I’m not sure that next year when I see the error message I will remember what part caused the error to be shown.

So I was thinking ahead by using a wild card that then I wouldn’t need to remember

So example.
The code would ignore anything between * *
Meaning if when I change *2022* to *1023* the code would still ignore it as it should treat * * as please ignore.
 
Upvote 0
Hi,
Maybe I didn’t explain correctly.
I’m not sure that next year when I see the error message I will remember what part caused the error to be shown.

So I was thinking ahead by using a wild card that then I wouldn’t need to remember

So example.
The code would ignore anything between * *
Meaning if when I change *2022* to *1023* the code would still ignore it as it should treat * * as please ignore.
If it's always a 4-digit number maybe:
VBA Code:
    If Target.Value = "NEVER" Or Target.Value = "TBA" Or Target.Value Like "####" Then Exit Sub
 
Upvote 0
Solution
.. and in the other case you create your own wildcard combination, eg $@ @$
VBA Code:
$@2022$@ Like $@*@$ equals TRUE     ' or
$@something$@ Like $@*@$ equals TRUE
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,052
Members
448,940
Latest member
mdusw

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