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

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
Do you have values in col A?
 
Upvote 0
Looks like what I previously was correct compare to your expected result. I hope this is correct. I'm assuming that column D is always blank when column A is 6. Otherwise it will just overwrite.

VBA Code:
Sub ToggleState()

Dim n As Long, eRow As Long
Dim State As String

' Find  end of data row in column A
eRow = Range("A1").End(xlDown).Row

' Go through rows and fill column D on what state of D when column A = 42
For n = 2 To eRow
    If Range("A" & n) = 42 Then State = Range("D" & n)
    If Range("A" & n) = 6 Then Range("D" & n) = State
Next

End Sub
 
Upvote 0
Do you have any merged cells on that sheet?

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.
Would it be simpler if you just sort the list by Col A and Col D?
 
Upvote 0

Forum statistics

Threads
1,214,631
Messages
6,120,645
Members
448,974
Latest member
DumbFinanceBro

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