Argument Not Optional error

Ironman

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

I have some existing code that was kindly provided to me that changes the validation details in a cell. I just need it to be simplified, so:

1. When I key a shortcut, the code runs, but only in sheet 'Training Log' in Col H of the last filled row and if the active cell isn't that cell, then that cell is selected and the code runs.

2. I don't need the font/alignment details as these need to remain as they are. I also don't need the "Training 1981-1997" part of the code and it can be deleted. I've tried to delete these myself but I've had an 'argument not optional' error and I didn't know where to start looking.
VBA Code:
Sub Fillcell(Color As Long, cValue As String)

    Application.EnableEvents = False
 
    With Selection
      .Font.Name = "Wingdings"
      .Font.Size = 12
      .Font.ColorIndex = 1
      .HorizontalAlignment = xlCenter
      .Value = cValue
 
      If ActiveSheet.Name = "Training Log" Then
        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
        ElseIf ActiveSheet.Name = "Training 1981-1997" Then
        With Selection.Validation
          .Delete
          .Add Type:=xlValidateInputOnly, AlertStyle:=xlValidAlertStop, Operator _
          :=xlBetween
          .IgnoreBlank = True
          .InCellDropdown = False
          .InputTitle = ""
          .ErrorTitle = ""
          .InputMessage = ""
          .ErrorMessage = ""
          .ShowInput = True
          .ShowError = True
        End With
      End If
 
    End With
 
    With Selection.Interior
      .ColorIndex = Color
      .Pattern = xlSolid
    End With
End Sub
 
    Application.EnableEvents = True
 
End Sub
Many thanks!
 
Last edited:
It is working on my side, perhaps your last filled cell in column H on sheet "Training Log" is not the cell you think it is?
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
After running the code, if you execute these lines in the immediate window do you get the results you expect.

? Sheets("Training Log").Range("H" & Sheets("Training Log").Rows.Count).End(xlUp).address

? Sheets("Training Log").Range("H" & Sheets("Training Log").Rows.Count).End(xlUp).validation.inputmessage

 
Upvote 0
This is WEIRD. It has just started working and it's perfect. I wish I knew why, I haven't changed anything - yes, the cell is the last row Col H.

The main thing is to say a big THANK YOU and apologise for complicating it.
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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