bakersburg9
Mar 17 2012, 04:04 PM
I'm working on a project where column E is report names, column F is code (A=Active, D=to be deleted, etc.), and column G is a date field - if there is a date in column G, then the code in column F HAS to be A - is there a way that I can have an onchange macro in my worksheet to where when a date is placed in Col. G, say for example cell G2, that an "A" is autiomatically placed in Cell F2 ? even better would be for it to look at the date, and if it was prior to 1/1/2012, then set the value in the adjacent cell in col F to D, since I would want to flag it (as an inactive report) for deletion, and if (the date in column G) was after 12/31/2011, then put an "A" in column F ?
Am I asking for the moon here ?
Bob G
Mar 18 2012, 07:48 AM
guerillaunit
Mar 22 2012, 01:43 PM
Right click on the tab name on the bottom of your workbook. Click on "View Code". Paste this in:
CODE
Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Value > #12/31/2011# Then
Range("f3").Value = "A"
Else
End If
If Target.Column = 7 And Target.Value < #1/1/2012# Then
Range("f3").Value = "D"
Else
End If
End Sub
bakersburg9
Mar 22 2012, 02:00 PM
Gunit,
That works perfect if I'm changing the value in cell G3, but what about G4, G5...... G653 ? How would I alter the VBA then ?
QUOTE
Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Value > #12/31/2011# Then
Range("f3").Value = "A"
Else
End If
If Target.Column = 7 And Target.Value < #1/1/2012# Then
Range("f3").Value = "D"
Else
End If
End Sub
Thanks for your help !
Steve
guerillaunit
Mar 23 2012, 10:00 AM
Try this edited version
QUOTE
Private Sub WorkSheet_Change(ByVal Target As Range)
If Target.Column = 7 And Target.Value > #12/31/2011# Then
Range("f" & Target.Row).Value = "A"
Else
End If
If Target.Column = 7 And Target.Value < #1/1/2012# Then
Range("f" & Target.Row).Value = "D"
Else
End If
If Target.Column = 7 And Target.Value = "" Then
Range("f" & Target.Row).Value = ""
Else
End If
End Sub
In addition to getting the rows to match between columns G and F, I've added an extra if statement so that if you deleted a date, the corresponding cell in Column F would also be cleared
bakersburg9
Mar 23 2012, 01:18 PM
QUOTE (guerillaunit @ Mar 23 2012, 03:00 PM)

edited version - In addition to getting the rows to match between columns G and F, I've added an extra if statement so that if you deleted a date, the corresponding cell in Column F would also be cleared
G-Unit, thanks for 'pimping' my workbook ! That is so AWESOME !!!! I love it - but is there a way to instead having the dates hard-coded in code, to have them point to a cell reference ? I tried to do that on the attached example, but it didnt' work - it just gives everything the code of "D" no matter the date
Bob G
Mar 23 2012, 01:31 PM
didnt we work on that exact answer in a previous thread of yours?
guerillaunit
Mar 23 2012, 03:02 PM
Sure, make the following changes
"> #12/31/2011# Then" → "> Sheets("ListsNotes").Range("G9").Value Then"
"< #1/1/2012# Then" → "< Sheets("ListsNotes").Range("G10").Value Then"