Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Rainhard Fischer   on Jan 17 In MS Office Category.

  
Question Answered By: Vid Fischer   on Jan 17

Couple of things....

Have you tried stepping through the code at all??

The code will be easier to read if indented and each "part" is on a seperate
line.
When it's seperated out you can step through the code much easier and see
what's going on.

FWIW, my personal preference... Is also to put all the Dims in one place.
I'd also change  all the literals to uppercase and test for the uppercase
values.
There's no value in selecting cells  to fill them/look in them, except in
tracking what's happening. Using ranges is usually quicker.
Most of that's personal preference though.

I suspect though that it's the syntax of the Find method that's the problem
though I can't quite see why at the moment.

I've seperated your code out below. What happens if you run it against your
sheet?


Start-------------
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal target  As Range)

Application.ScreenUpdating = False

Dim LastRow
Dim row
Dim response

LastRow = Cells.Find _
("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).row


For row  = 2 To LastRow
If UCase(Range("I" & row).Value) = "BIGSUPPLIER" Then

If UCase(Range("AI" & row).Value) = "ONETHING" Then

Range("AQ" & row).Select
ActiveCell.FormulaR1C1 = "L"

ElseIf UCase(Range("AI" & row).Value) = "OTHERTHING" Then

Range("AQ" & row).Select
ActiveCell.FormulaR1C1 = "X"

Else

'If not any of those things, turn  row RED
Range("A" & row, "AR" & row).Interior.Color = _
RGB(255, 0, 0)

response = MsgBox _
("The following is a list  of acceptable" _
& " values  for the Rep/OSR field  when" _
& " the supplier is BIGsupplier" _
& vbCr _
& " The value you have entered  is not" _
& " one of these allowed values." _
& " Please change this value." _
, vbOKOnly)
End If

End If

Next

Application.ScreenUpdating = True

End Sub
End

Share: 

 

This Question has 17 more answer(s). View Complete Question Thread

 


Tagged: