Worksheet Change by Value

Aussie Grid

New Member
Joined
Jan 14, 2010
Messages
47
I would like to be able to compare the target value to that of a range of cells, thus avoiding code for every target cell.
Currently: If Target.Offset(0, -1).Value = Worksheets("Admin").Range("S33")
If it could be changed to look for the target cell value eg. Worksheets("Admin").Range("S33:S40") it would save a lot of code as Ialready have about 240 lines of code in the event.
Would it be better as a case statement?

Any & all help appreciated

Aussie Grid
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
See if below what u want

Code:
for i = 1 to worksheets("Admin").Range("S33:S40").rows.count
     if Target.offset(0,-1).value = worksheets("Admin").Range("S33:S40").cells(i)
         Msgbox "Hi"
     End if
Next i
 
Last edited:
Upvote 0
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count > i Then Exit Sub
Dim C As Range
Set C = Range("S33:S40").Find(Target.Offset(0, -1), LookIn:=xlValues)
If Not C Is Nothing Then
      MsgBox "Found in " & C.Address
Else: MsgBox "Not Found"
End If
End Sub

lenze
 
Upvote 0
Or code like below:
Just need to chage The "S3:10,R6:R18" to the range u want.

Code:
Sub Try()

Dim RangArea As Range
Dim i, j As Integer

Set RangArea = Worksheets("Admin").Range("S3:S10,R6:R18")

For i = 1 To RangArea.Areas.Count
    For j = 1 To RangArea.Areas(i).Cells.Count
        If Target.Offset(0, -1).Value = RangArea.Areas(i).Cells(j).Value Then
            MsgBox "Hi"
        End If
    Next j
Next i

End Sub
 
Upvote 0
Thank you both for your time and effort they all worked perfectly and will save a lot of typing.

Thank you

Aussie Grid
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,843
Members
449,051
Latest member
excelquestion515

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