If Target And Or Then - Pointers?

spydey

Active Member
Joined
Sep 19, 2017
Messages
314
Office Version
  1. 2013
Platform
  1. Windows
Hey there guys,

I am trying to get this worksheet_Change to work correctly for what I need. I am pretty tired so I am probably not thinking straight.

I have a drop-down list in column F, known as Status, it allows me to select a Pending, Pass, Fail, or leave the cell blank as the input. In column G, known as Date Completed, I am trying to input a date automatically when the contents of column F are changed to either Pass or Fail.

I can get a date in G if anything in column F changes, but I only want it to show the date when column F is either Pass or Fail. I just can't seem to get it. Too many long nights and not enough sleep lately.

Here is the code I am using:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)    If (Target.Count = 6) And _
       (Not Intersect(Target, [G:G]) Is Nothing) Then _
        Target.Offset(0, 1) = Date
End Sub

I thought that I had it when I tried:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)    If (Target.Count = 6) And _
       (Target = "Pass" OR Target = "Fail") And _
       (Not Intersect(Target, [G:G]) Is Nothing) Then _
        Target.Offset(0, 1) = Date
End Sub

But that was a no go.

Any thoughts or advise to point me in the right direction?

Thank you everyone!
 
@ Fluff,

Thanks so very much! Worked like a charm!

Here is my final code:

Code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)

    If Target.Count = 1 And Target.Column = 6 Then
        If UCase(Target.Value) = "PASS" Or UCase(Target.Value) = "FAIL" Then
            Target.Offset(0, 1) = Date
        Else
            Target.Offset(0, 1).ClearContents
        End If
    End If


End Sub

Thanks again very much. I have only been working with VBA for about 2 weeks now and am learning a ton, so your willingness and disposition to assist me is very much appreciated.

-Spydey
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.

Forum statistics

Threads
1,224,827
Messages
6,181,199
Members
453,022
Latest member
RobertV1609

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