charlests

New Member
Joined
Oct 19, 2013
Messages
9
Hi, I need a macro with following conditions,

1) If cells in column A is equal to any one of the cells in column G then
2) The corresponding cell value in column C should say "Match"
3) If not, the correcsponding cell value in column C should say "Not Match"

I am a beginner in Macro and I have tried one macro with x and y as variables but not getting the result I wanted, if you could help me with the macro code, it would be very helpful for me.
Thanks in advance
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
if it must be a macro do the logic in stages. for every cell in column A look for a match in EVERY cell in column G - as soon as match is found, stop, and put match in column C - if macro completes without finding match put "not match" in C

say you have 10 rows of data

for j=1 to 10
for k= 1 to 10

k cycles through every row while J holds on row 1

can you now do the logic yourself ?
 
Upvote 0
if it must be a macro do the logic in stages. for every cell in column A look for a match in EVERY cell in column G - as soon as match is found, stop, and put match in column C - if macro completes without finding match put "not match" in C

say you have 10 rows of data

for j=1 to 10
for k= 1 to 10

k cycles through every row while J holds on row 1

can you now do the logic yourself ?

Thanks for your reply, I have tried similar to that, it goes like this

Sub match()
Dim x As Integer
Dim y As Integer
For x = 7 To 10
For y = 7 To 12
If Cells(x, 1) = Cells(y, 7) Then
Cells(x, 3).Value = "Match"
Else
Cells(x, 3).Select
ActiveCell.Offset(-2, -2).Copy
Cells(x, 3).Select
ActiveSheet.Paste
End If
Next y, x
End Sub


Im not getting the result I wanted with this macro, as I am beginner to macro, please send the full code. Thanks again
 
Upvote 0
charlests,

1. What version of Excel and Windows are you using?

2. Are you using a PC or a Mac?

In the future when asking for help you should give us a screenshot of your raw data, and, also give us a screenshot of what the results should look like.

If I understand you correctly.

I assume that your raw data contains titles in row 1.

And, you only have to loop thru column A.

Sample raw data:


Excel 2007
ABCDEFG
1Title ATitle BTitle CTitle DTitle ETitle FTitle G
2111
3212
435
548
6513
7614
872
9815
10916
11103
12
Sheet1


After the macro:


Excel 2007
ABCDEFG
1Title ATitle BTitle CTitle DTitle ETitle FTitle G
21Not Match11
32Match12
43Match5
54Not Match8
65Match13
76Not Match14
87Not Match2
98Match15
109Not Match16
1110Not Match3
12
Sheet1


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code
2. Open your NEW workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Sub MatchAtoG()
' hiker95, 05/02/2014, ME775105
Dim c As Range, grng As Range
Application.ScreenUpdating = False
For Each c In Range("A2", Range("A" & Rows.Count).End(xlUp))
  Set grng = Columns(7).Find(c, LookAt:=xlWhole)
  If grng Is Nothing Then
    c.Offset(, 2).Value = "Not Match"
  ElseIf Not grng Is Nothing Then
    c.Offset(, 2).Value = "Match"
    Set grng = Nothing
  End If
Next c
Columns(3).AutoFit
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the MatchAtoG macro.
 
Upvote 0

Forum statistics

Threads
1,214,806
Messages
6,121,667
Members
449,045
Latest member
Marcus05

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