VBA: For Each Match Return Adjacent Cell

BenGee

Board Regular
Joined
Mar 5, 2016
Messages
196
Hi

Here's what I have so far;
Code:
    For Each c In Worksheets("Rota").Range("A3:A31")
        If Not IsError(Application.Match(c, Worksheets("Key").Range("A16:A41"), 0)) Then
            [COLOR="#FF0000"]Worksheets("Rota").c.Offset(0, 1).Value = Worksheets("Key").Match.c.Offset(0, 1).Value[/COLOR]
        End If
    Next

The red line seems to cause problems. The result should be for each match, the adjacent cell value in "Rota" to be the same as the adjacent cell value in "Key".

Any ideas how I can get this to work would be hugely appreciated. Thank you

Edit: By problems, I mean a 'Run-time error '438' - Object doesn't support this property or method'. Sorry should've been more specific.
 
Last edited:

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
How about
Code:
Dim x As Variant
For Each c In Worksheets("Rota").Range("A3:A31")
   x = Application.Index(Worksheets("Key").Range("B16:B41"), Application.Match(c, Worksheets("Key").Range("A16:A41"), 0))
    If Not IsError(x) Then
        Worksheets("Rota").c.Offset(0, 1).Value = x
    End If
Next
 
Upvote 0
Try:-
Code:
[COLOR="Navy"]Sub[/COLOR] MG23Apr15
 [COLOR="Navy"]Dim[/COLOR] c [COLOR="Navy"]As[/COLOR] Range, Rngk [COLOR="Navy"]As[/COLOR] Range
 [COLOR="Navy"]Set[/COLOR] Rngk = Worksheets("Key").Range("A16:A41")
 [COLOR="Navy"]For[/COLOR] [COLOR="Navy"]Each[/COLOR] c [COLOR="Navy"]In[/COLOR] Worksheets("Rota").Range("A3:A31")
        [COLOR="Navy"]If[/COLOR] Not IsError(Application.Match(c, Rngk, 0)) [COLOR="Navy"]Then[/COLOR]
              c.Offset(0, 1).Value = Rngk.Parent.Range("B" & Application.Match(c, Rngk, 0) + 15)
        [COLOR="Navy"]End[/COLOR] If
    [COLOR="Navy"]Next[/COLOR]
[COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]
Regards Mick
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,996
Members
452,542
Latest member
Bricklin

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