Jon
Jon

Reputation: 433

Filtering a row based on the first four digits and last four digits of number is one column

So I have been using in some macros coding to filter rows based on the values in one column. This has worked for what I've done in a general sense, but I'm needing to do some things that are a little more specific with the same stuff. What I have been using is follows this:

 Dim c As Range, x As Integer
'other code here
Set c = shtMaster.Range("Y5")  'Start search in Row 5
'other code  here
While Len(c.Value) > 0
        'If value in column Y ends with specified value,copy to report sheet
        If c.Value Like "*2130" Or c.Value Like "*0853" Then
'rest of macro follows

I've been trying to mess with the If line so that I can add conditions for the first four and last four digits instead of just using values based on the last four. For example, I may want to search Column Y for all values whose first four digits are "1234*" but whose last four digits are not "*5678". So if I had a spreadsheet with:

     Column Y  

Row 1 12345678
Row 2 12341234
Row 3 12340000

then it would pull rows 2 and 3 but not row 1. I would like to use the structure above since that's how everything is already written, but I can't seem to get the syntax right. Is what I want to do possible with the structure I already have written? If so, any suggestions? Thanks.

Upvotes: 0

Views: 1616

Answers (1)

NoAlias
NoAlias

Reputation: 9193

If c.Value Like "1234*" And Not c.Value Like "*5678" Then 

'Values start with 1234 and do not end in 5678.

End If

Upvotes: 3

Related Questions