Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default Triming trailing spaces before using Match on columns of numbers withleading zeroes formatted as text

The following code given to me previously by Marcus here worked fine
until I appliedd it, to the real case .
Not obvious to the eye, for apparently same visual content, the
target cells to be Matched to the
Reference cells had 2 trailing spaces. Reference cells had a Length of
8 vs 10 for the Target cells
..
The question is :
In my For Each RngCell loop, what is the syntax to replace the Target
value with a Trim of that Target value
before I use Application.Match.
..
Sub FlagMatchingRecords()
Dim RngCell As Range
Dim IsMatch() As Variant
Dim res As Variant
Dim lw As Long
Dim lr As Long
Dim X As Range
Dim wb As Workbook
Dim ws As Worksheet
lr = Range("B" & Rows.Count).End(xlUp).Row
Set wb = Workbooks("B.xls")
Set ws = wb.Sheets("Sheet1")
IsMatch() = Range("B1:B" & lr).Value
lw = ws.Range("A" & Rows.Count).End(xlUp).Row


Set X = ws.Range("A1:A" & lw)
For Each RngCell In X
MsgBox RngCell.Value
res = Application.Match(RngCell.Value, IsMatch, 0)
If IsError(res) Then
'No Match
Else ' Match
RngCell.Interior.Color = vbYellow
End If
Next RngCell
End Sub
..
Help appreciated,

J.P.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Triming trailing spaces before using Match on columns of numbers with leading zeroes formatted as text

Do it while executing Application.Match:

res = Application.Match(Trim(RngCell.Value), IsMatch, 0)




"u473" wrote in message
...
The following code given to me previously by Marcus here worked fine
until I appliedd it, to the real case .
Not obvious to the eye, for apparently same visual content, the
target cells to be Matched to the
Reference cells had 2 trailing spaces. Reference cells had a Length of
8 vs 10 for the Target cells
.
The question is :
In my For Each RngCell loop, what is the syntax to replace the Target
value with a Trim of that Target value
before I use Application.Match.
.
Sub FlagMatchingRecords()
Dim RngCell As Range
Dim IsMatch() As Variant
Dim res As Variant
Dim lw As Long
Dim lr As Long
Dim X As Range
Dim wb As Workbook
Dim ws As Worksheet
lr = Range("B" & Rows.Count).End(xlUp).Row
Set wb = Workbooks("B.xls")
Set ws = wb.Sheets("Sheet1")
IsMatch() = Range("B1:B" & lr).Value
lw = ws.Range("A" & Rows.Count).End(xlUp).Row


Set X = ws.Range("A1:A" & lw)
For Each RngCell In X
MsgBox RngCell.Value
res = Application.Match(RngCell.Value, IsMatch, 0)
If IsError(res) Then
'No Match
Else ' Match
RngCell.Interior.Color = vbYellow
End If
Next RngCell
End Sub
.
Help appreciated,

J.P.



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Text with repeating trailing spaces briancrosier Excel Worksheet Functions 4 March 11th 09 12:51 PM
Remove trailing spaces from multiple columns in Excel dcaissie Excel Worksheet Functions 8 May 16th 08 08:21 PM
how do I remove empty spaces trailing a text string? Need_Help Excel Worksheet Functions 2 June 7th 05 12:13 AM
getting rid of trailing zeroes Wazooli Excel Programming 11 March 2nd 05 08:09 PM
Padding formatted numbers with leading spaces Don Wiss Excel Programming 6 January 25th 05 12:47 PM


All times are GMT +1. The time now is 10:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"