Argument not optional error

svjensen

Board Regular
Joined
Jun 10, 2009
Messages
118
I am trying to pass variables to a sub routine, which must then establish an log based on the variables.

But I keep getting the following error:
"Compile error: Argument not optional"

As far as I understand this error indicates, that I have omitted a variable, but that is not the case. Can anyone help?

I call the procedure using:
Code:
Call WriteToLog(CurrentFileShort, Projektejer, fnameshort, SourceSheet_BCnumber, SourceRange_BCnumber, ErrorText, link)

The procedure it self is:
Code:
Sub WriteToLog(TargetFile As String, TargetSheet As String, shSkabelon as String, SourceFileShort As String, SourceSheet_BCnumber As String, SourceRange_BCnumber As String, ErrorText As String, SourceFileLong As String)
 
    Workbooks(TargetFile).Activate
    Workbooks(TargetFile).Sheets(TargetSheet).Select
    Range("B1").Select
    Call GoToLastRow
    ActiveCell.Offset(0, 0) = Workbooks(SourceFileShort).Sheets(SourceSheet_BCnumber).Range(SourceRange_BCnumber)
    ActiveCell.Offset(0, 1) = ErrorText
    ActiveCell.Offset(0, 2).select
    ActiveCell.Hyperlinks.Add Anchor:=Selection, Address:=SourceFileLong, TextToDisplay:=SourceFileLong
End SUb
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Um, yes you have left out an argument...

The function you wrote requires 8 arguments - I've numbered them.
Rich (BB code):
Sub WriteToLog(1TargetFile As String, 2TargetSheet As String, 3shSkabelon as String, 4SourceFileShort As String, 5SourceSheet_BCnumber As String, 6SourceRange_BCnumber As String, 7ErrorText As String, 8SourceFileLong As String)

But the code you wrote to call the function, only gives 7, I've numbered them
Rich (BB code):
Call WriteToLog(1CurrentFileShort, 2Projektejer, 3fnameshort, 4SourceSheet_BCnumber, 5SourceRange_BCnumber, 6ErrorText, 7link)

Also, one of the arguments in your function, is not actually used in the function, I colored it Blue.
 
Last edited:
Upvote 0
Well, that is quite embarassing
Apprantly, I had not updated all my calls.

Thanks for the help - and I am sorry for the inconvenience.

/Soren
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,542
Members
449,316
Latest member
sravya

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