Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default check value with array, Application.Match

Hi, I'm trying to copy rows to 2 others sheets, looping through cells
if cell value match with one of array value. But it copies all rows. It
seems, that application.match doesn't work properly.

My code:

Sub makro()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim RngCell As Range
Dim nettingList() As Variant
Dim res As Variant
'Set wks = .Worksheets("wejscia T")
nettingList() = Array("UK", "GE", "FR", "IT", "SP", "HK", _
"US", "INT", "IRL", "CZ", "JP")
With Workbooks(ActiveWorkbook.Name)
Set wsA = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
Set wsB = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
wsA.Name = "wejscia T netting"
wsB.Name = "wejscia T outnet"
With .Worksheets("wejscia T Avon 2005")
.Rows(1).Copy Destination:=wsA.Range("A1")
.Rows(1).Copy Destination:=wsB.Range("A1")
For Each RngCell In .Range("C2:C" & .Range("C" &
..Rows.Count).EndxlUp).Row)
res = Application.WorksheetFunction.Match(RngCell.Value, nettingList)
If IsError(res) Then
With wsB
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
Else
With wsA
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
End If
Next RngCell
End With
End With
End Sub

How should I use Application.Match function to correct this?

Przemek

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default check value with array, Application.Match

Sub makro()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim RngCell As Range
Dim nettingList() As Variant
Dim res As Variant
'Set wks = .Worksheets("wejscia T")
nettingList() = Array("UK", "GE", "FR", "IT", "SP", "HK", _
"US", "INT", "IRL", "CZ", "JP")
With Workbooks(ActiveWorkbook.Name)
Set wsA = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
Set wsB = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
wsA.Name = "wejscia T netting"
wsB.Name = "wejscia T outnet"
With .Worksheets("wejscia T Avon 2005")
.Rows(1).Copy Destination:=wsA.Range("A1")
.Rows(1).Copy Destination:=wsB.Range("A1")
For Each RngCell In .Range("C2:C" & .Range("C" &
.Rows.Count).End(xlUp).Row)
res = Application.Match(RngCell.Value, nettingList)
If IsError(res) Then
With wsB
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
Else
With wsA
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
End If
Next RngCell
End With
End With
End Sub

--
Regards,
Tom Ogilvy

"Przemek" wrote in message
oups.com...
Hi, I'm trying to copy rows to 2 others sheets, looping through cells
if cell value match with one of array value. But it copies all rows. It
seems, that application.match doesn't work properly.

My code:

Sub makro()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim RngCell As Range
Dim nettingList() As Variant
Dim res As Variant
'Set wks = .Worksheets("wejscia T")
nettingList() = Array("UK", "GE", "FR", "IT", "SP", "HK", _
"US", "INT", "IRL", "CZ", "JP")
With Workbooks(ActiveWorkbook.Name)
Set wsA = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
Set wsB = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
wsA.Name = "wejscia T netting"
wsB.Name = "wejscia T outnet"
With .Worksheets("wejscia T Avon 2005")
.Rows(1).Copy Destination:=wsA.Range("A1")
.Rows(1).Copy Destination:=wsB.Range("A1")
For Each RngCell In .Range("C2:C" & .Range("C" &
.Rows.Count).EndxlUp).Row)
res = Application.WorksheetFunction.Match(RngCell.Value, nettingList)
If IsError(res) Then
With wsB
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
Else
With wsA
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
End If
Next RngCell
End With
End With
End Sub

How should I use Application.Match function to correct this?

Przemek



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default check value with array, Application.Match

Hi Tom, it's still doesn't work as I want to. E.g. if in rngCell is
value TU, it's still copy that row to wsA sheet. What I want to achieve
is, that all rows with RngCell.Value, which match one of array's member
will be copied to sheet wsA, others rows to sheet wsB.

Przemek

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default check value with array, Application.Match

The code worked fine for me. The records that matched were copied to
netting and those that didn't were copied to outnet.

Perhaps you have embedded blanks or something in column C.

--
Regards,
Tom Ogilvy

"Przemek" wrote in message
oups.com...
Hi Tom, it's still doesn't work as I want to. E.g. if in rngCell is
value TU, it's still copy that row to wsA sheet. What I want to achieve
is, that all rows with RngCell.Value, which match one of array's member
will be copied to sheet wsA, others rows to sheet wsB.

Przemek



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 129
Default check value with array, Application.Match

Hi,

I didn't test your code. but, if you want an exact match,
try this (the 3rd parameter is 0)

res = Application.Match(RngCell.Value, nettingList, 0)

--
HTH,

okaizawa


Przemek wrote:
Hi, I'm trying to copy rows to 2 others sheets, looping through cells
if cell value match with one of array value. But it copies all rows. It
seems, that application.match doesn't work properly.

My code:

Sub makro()
Dim wsA As Worksheet
Dim wsB As Worksheet
Dim RngCell As Range
Dim nettingList() As Variant
Dim res As Variant
'Set wks = .Worksheets("wejscia T")
nettingList() = Array("UK", "GE", "FR", "IT", "SP", "HK", _
"US", "INT", "IRL", "CZ", "JP")
With Workbooks(ActiveWorkbook.Name)
Set wsA = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
Set wsB = .Worksheets.Add(After:=.Sheets(.Sheets.Count))
wsA.Name = "wejscia T netting"
wsB.Name = "wejscia T outnet"
With .Worksheets("wejscia T Avon 2005")
.Rows(1).Copy Destination:=wsA.Range("A1")
.Rows(1).Copy Destination:=wsB.Range("A1")
For Each RngCell In .Range("C2:C" & .Range("C" &
.Rows.Count).EndxlUp).Row)
res = Application.WorksheetFunction.Match(RngCell.Value, nettingList)
If IsError(res) Then
With wsB
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
Else
With wsA
RngCell.EntireRow.Copy Destination:= _
.Range("A" & .Rows.Count).End( _
xlUp).Offset(1, 0)
End With
End If
Next RngCell
End With
End With
End Sub

How should I use Application.Match function to correct this?

Przemek



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default check value with array, Application.Match

Tx for help, it works now.

Przemek

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
Match using array of column and row references to match with jkfin1 Excel Worksheet Functions 1 September 16th 08 04:39 PM
index match array function-returning only first match, need last. Julie Olsen Excel Worksheet Functions 3 December 29th 06 12:50 AM
application.match Chip Smith Excel Discussion (Misc queries) 3 March 30th 06 08:56 PM
Application.Match SIGE Excel Programming 4 March 30th 05 03:06 PM
Using Application.match against one dimension of a multidimensional array? KR Excel Programming 1 January 24th 05 10:01 PM


All times are GMT +1. The time now is 01:53 PM.

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

About Us

"It's about Microsoft Excel"