Minor amendment needed for code to run

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi

The following code in the worksheet_change event is triggered when any text value other than 'OTHER' and 'REST' is input in column B in the last filled row. The input text "Double click for lifetime mileage total up to this date" is then added to the validation in Column H.
VBA Code:
If target.Column = 2 And target.Value <> "OTHER" And target.Value <> "REST" Then
    Application.EnableEvents = False
    With Range("A23358").End(xlUp).Offset(1, 7).Validation
         .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator:=xlBetween
         .InputMessage = "Double click for lifetime mileage total up to this date"
         .ShowInput = True
       End With
   Application.EnableEvents = True
End If
I'm pretty close, but I can't quite get the first 3 lines right for the code to run.

Help would be appreciated.

Many thanks!
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
When putting a breakpoint on that first line does the code actually break there when you make a change in column B ?
If so, does F8 step through each of the following lines ?
 
Upvote 0
Hi Nolan

It errors 424 "Object Required"
 
Upvote 0
VBA Code:
If target.Column = 2 And target.Value <> "OTHER" And target.Value <> "REST" Then
 
Upvote 0
if you comment out everything between the IF line and the End IF line do you still get that?
 
Upvote 0
I don't see anything wrong with that IF line.

I just pasted the code from post 1 to the end of the Worksheet_Change Event before the call to ImportantMessages in the last file you provided and it doesn't give any error on that line, although it does error (1004 - Application-defined or object-defined error) on the .Add Type line.

I know nothing about data validation like that so will probably be searching the web for a while.

Sorry I can't help with this.
 
Upvote 0
No worries, thanks for trying. I know the data validation line works OK, I've used that before.
 
Upvote 0
Something that looks a little odd to me, "target" is in lower case, when it typically is in upper case, i.e. "Target".
It leads me to believe that perhaps you declared your own "target" variable, which could conflict with the imbedded parameter in the "Worksheet_Change" even procedure.

Could you please post the entire block of code you have for this procedure?
 
Upvote 0

Forum statistics

Threads
1,214,887
Messages
6,122,095
Members
449,064
Latest member
Danger_SF

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