How to search for a value in a range if found run a procedure.

Solved/Closed
Tiny - Apr 29, 2015 at 10:14 AM
 Tiny - Apr 29, 2015 at 11:53 AM
Hello,

I am trying to get my spread sheet to run a Macro I have that is working nicely (that copies the row and pastes it to another sheet in the workbook) automatically when i type in Lost in a certain cell. (range L6-L100)

Here is the code i used

Sub Worksheet_Change()

If Target.Cells = "L6:L100" Then
If Value = "Lost" Then
CopyCells

End If
End If

End Sub

this was placed in sheet2 VBA code as i only wanted it to apply to this sheet2.

Any idea's what i have done wrong it has been a long time since i used VB in Excell in anger.



Related:

2 responses

MaxStart Posts 339 Registration date Tuesday March 3, 2015 Status Moderator Last seen July 3, 2015 69
Apr 29, 2015 at 10:45 AM
You need to trigger the macro while the Worksheet_Change event occurs
and what cell will contain the text "Lost", or is it going to be in a range?
0
So if i use

private sub worksheet_change()??

Also i want to be able to pick up from the range L6 to L100 for the text Lost to trigger my macro Copycells,
0
MaxStart Posts 339 Registration date Tuesday March 3, 2015 Status Moderator Last seen July 3, 2015 69
Apr 29, 2015 at 11:42 AM
to get to the workshet_change event: hit Alt + F11 to get to the developer window



use this code to check the range L6 to L100 for the word "Lost"
please note that this is case sensitive:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
i = 6
Do Until i = 100
    If Cells(i, 12).Value = "Lost" Then
        CopyCells
    End If
    i = i + 1
Loop
End Sub


Je ne parle pas français, mais je l'aime.
je ne pas change.
0
Thank you works great!
0