Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default VBA equivalent for worksheet 'match'?

I want to copy a column to one of several other cols, based on matching
one cell in the first col to corresponding cells in the other cols. Eg:

A B C D E
-----------------------
1 b a b c d
2 1
3 2
4 3
5 4
6 5
7 6

A1 contains the index ('b'), and B1:E1 are the values to match that
against ('a .. d'). In this case, I'd want to copy col A to col C.

I can do this by using another cell (say A8) to determine an offset:

A8 = match(A8,B1:E1)

Together with the macro ...

Sub Macro1()
Range("A1:A7").Copy
Range("A1:A7").Offset("0", Range("A8").Value).PasteSpecial _
xlPasteValues
End Sub

Is there a way to do this strictly in VBA - ie, w/o the 'match' cell
(A8)?

Thanks,
George
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 857
Default VBA equivalent for worksheet 'match'?

George,

One way:

Sub Macro1()
Dim iColOffset As Long
iColOffset = WorksheetFunction.Match(Range("A1"), Range("B1:E1"))
Range("A1:A7").Copy
Range("A1:A7").Offset(0, iColOffset).PasteSpecial xlPasteValues
End Sub


--
Hope that helps.

Vergel Adriano


"George" wrote:

I want to copy a column to one of several other cols, based on matching
one cell in the first col to corresponding cells in the other cols. Eg:

A B C D E
-----------------------
1 b a b c d
2 1
3 2
4 3
5 4
6 5
7 6

A1 contains the index ('b'), and B1:E1 are the values to match that
against ('a .. d'). In this case, I'd want to copy col A to col C.

I can do this by using another cell (say A8) to determine an offset:

A8 = match(A8,B1:E1)

Together with the macro ...

Sub Macro1()
Range("A1:A7").Copy
Range("A1:A7").Offset("0", Range("A8").Value).PasteSpecial _
xlPasteValues
End Sub

Is there a way to do this strictly in VBA - ie, w/o the 'match' cell
(A8)?

Thanks,
George

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 14
Default VBA equivalent for worksheet 'match'?

On Fri, 20 Apr 2007 05:36:04 -0700, Vergel Adriano
wrote:

,,,,


Hope that helps.


Yes, thanks.

G
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 two cells from one worksheet to another Barb Excel Worksheet Functions 3 October 30th 06 02:35 PM
Match 2 worksheet mohsin Excel Worksheet Functions 1 August 12th 06 01:46 PM
Match and merge on new worksheet Traci Excel Worksheet Functions 1 May 12th 06 08:24 AM
using index, match on another worksheet elrussell Excel Worksheet Functions 1 March 8th 06 06:25 AM
Match a value from a column in worksheet WilliamVierra Excel Worksheet Functions 2 August 10th 05 04:49 PM


All times are GMT +1. The time now is 04: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"