VBA to find a value in different cell and mark as Y

Joined
Oct 26, 2020
Messages
7
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2011
  6. 2010
  7. 2007
Platform
  1. Windows
ABCd
42081204*MGY
608120402236979
608120402237371
608120402245293
608120402245644
608120402281279
42081204MgN
608120402024152

I have the above data.

Col A- will have values like 6,42,41 etc.. , for this i am intrested only in 42 and 6
Col D - will have Y or N for all value in col A=42

i want to write a VBA to check if COL D has Y , If it is Y then i want Y as value in Col D to fill , only those which has number as 6 in Col A.

This set repeats in the table.
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
I do not understand what you mean by this:

i want to write a VBA to check if COL D has Y ,
If it is Y then i want Y as value in Col D to fill , only those which has number as 6 in Col A.
 
Upvote 0
confused, too.
better to use formula by 'if' condition.
 
Upvote 0
What value you want to fill in column D? If column D is N, no need to write value?
It is easy to understand if you show what is the expected result in this case
 
Upvote 0
I do not understand what you mean by this:

i want to write a VBA to check if COL D has Y ,
If it is Y then i want Y as value in Col D to fill , only those which has number as 6 in Col A.
I new to writing a macro , i want to fill the subsequent cells under col D Y if COL D =Y and Col A =6 and likewise N if col D=N and Col A=6
 
Upvote 0
Still not entirely clear but maybe
VBA Code:
Sub christopherlewis()
   Dim Rng As Range, Cl As Range
   
   For Each Rng In Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Areas
      If Rng.Offset(-1)(1) = "Y" Then
         For Each Cl In Rng
            If Cl.Offset(, -3) = 6 Then Cl.Value = "Y"
         Next Cl
      End If
   Next Rng
End Sub
 
Upvote 0
Still not entirely clear but maybe
VBA Code:
Sub christopherlewis()
   Dim Rng As Range, Cl As Range
  
   For Each Rng In Range("D2:D" & Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlBlanks).Areas
      If Rng.Offset(-1)(1) = "Y" Then
         For Each Cl In Rng
            If Cl.Offset(, -3) = 6 Then Cl.Value = "Y"
         Next Cl
      End If
   Next Rng
End Sub
Thank you so much , it is not executing somehow there is a debug error , what i want is as below

ABCdIf D2=Y or N and A2=6 then Y or N
42081204*100MGYY
608120402236979Y
608120402237371Y
608120402245293Y
608120402245644Y
608120402281279Y
4208120410MgNN
608120402024152N
 
Upvote 0
What is the error message & number & what line is highlighted when you click debug?
 
Upvote 0
What is the error message & number & what line is highlighted when you click debug?
Highlighted in the below line

If Rng.Offset(-1)(1) = "Y" Then
 

Attachments

  • err.PNG
    err.PNG
    21.6 KB · Views: 3
Upvote 0
Do you have any merged cells on that sheet?
 
Upvote 0

Forum statistics

Threads
1,215,235
Messages
6,123,786
Members
449,125
Latest member
shreyash11

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