Small amendment needed in code

Ironman

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

The below code (which I didn't write) includes a data validation entry.

Right now, the data validation applies to whichever sheet I run the macro in.

What I'm after is for the data validation code to only run in sheet1.

Code:
Sub Fillcell(Worksheet As Integer, color As Integer, cValue As String)

Application.EnableEvents = False
If Worksheet = 2 Or 14 Then
With Selection
.Font.Name = "Wingdings"
.Font.Size = 12
.Font.ColorIndex = 1
.Value = cValue
With Selection.Validation
        .Delete
        .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
        :=xlBetween
        .IgnoreBlank = True
        .InCellDropdown = False
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = "Double click for lifetime mileage total up to this date"
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End With
End If

With Selection.Interior
.ColorIndex = color
.Pattern = xlSolid
End With

Application.EnableEvents = True
End Sub

Many thanks!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Perfect, it works brilliantly now - thank you ever so much Rick.

I thought Sheet1 would be recognised, clearly not!

I clicked on your mini blog earlier and OMG your depth of knowledge is astounding, I feel so inferior!
 
Last edited:
Upvote 0
I clicked on your mini blog earlier and OMG your depth of knowledge is astounding,
Thank you, that is very kind of you to say. Just so you know, there are other volunteers here who know more than I do... I am just happy I am able to be of assistance to some of those who come here for answers to questions they have.



I feel so inferior!
Don't... if you can get the code you want to work, then that is all that really matters. As for what I know programming-wise... I have been programming since 1981 and have literally written code every day since. After 35+ years, you kind learn a thing or two as well as develop your own programming techniques in the process.
 
Last edited:
Upvote 0
Thanks again Rick - this forum is certainly full of amazing (and patient!) folk.

Best regards
 
Upvote 0

Forum statistics

Threads
1,216,471
Messages
6,130,822
Members
449,595
Latest member
jhester2010

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