rtour957 formulated on Tuesday :
'GS[_2_ said:
;1609211']Sorry.., I wasn't aware of your skills level. Yes, the code
does not
work "as is" and so here is a complete macro that you can paste into a
standard module. To do this, open the VBE (Alt+F11) and right-click
your project (workbook name listed in the Project Explorer pane) and
select Insert>Module from the context menu. Then paste this sub into
the code window that appears...
Sub RejectAdjacentData()
Dim c As Range, sz As String, lRow As Long
For Each c in Range("B1:B4")
sz = c.Text: lRow = c.Row
c.Formula = _
"=IF($A" & lRow & "=""NO""," & sz & " rejected," & sz & ")"
Next 'c
End Sub
Thanks for catching the missing quotes!
To use the macro enter Alt+F8 on the keyboard and select the macro in
the list, then click 'Run' to execute.
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion
I pasted the macro into the VBE but putting "no" to any of the cells in
A does not add the string "rejected" to the existing value in B. I
attached the file I had the macro in. Would be able to check why it's
not working?
Thank you for your patience,
Art
+-------------------------------------------------------------------+
+-------------------------------------------------------------------+
Entering "no" doesn't 'trigger' the macro. You must 'run' the macro
after entering "no". You did not put the code in a standard module as
instructed, but not to worry..! To have Excel run the macro
automatically you need to right-click the sheet tab, choose 'View
Code', and replace the previous code with the following...
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A1:A4")) Is Nothing Then Call
RejectAdjacentData(Target)
End Sub
Sub RejectAdjacentData(Rng As Range)
Dim sz$, sr$, sFormula$
With Rng.Offset(0, 1)
sz = .Text: sr = CStr(.Row)
sz = Replace(sz, " rejected", "") '//in case already done
sFormula = "=IF(UPPER($A" & sr & ")=""NO""," '//set condition
sFormula = sFormula & Chr(34) & sz & " rejected""," '//=condition
true
sFormula = sFormula & Chr(34) & sz & Chr(34) & ")" '//=condition
false
.Formula = sFormula
End With
End Sub
...so IF you enter "no" you WILL be able to 'undo' it after it changes
B.
But, IMO, you might be better of to use Conditional Formatting to
'flag' rejections rather than edit cell content. This way you never
lose the original data but still know whether it got rejected or not.
To implement a 'flag' in B1:B4, just have CF change the cell color.
Select B1:B4 and use the following formula in the CF condition criteria
box...
=UPPER($A1)="NO"
...and click the 'Format...' button to set a dotted border outline and
red pattern. (The dotted border will simulate gridlines if contiguous
cells are flagged)
Optionally, you could do both!
--
Garry
Free usenet access at
http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion