Wrong Number Of Arguments or invalid property assignment...Sometimes. Advice pls.

Willow123

New Member
Joined
Dec 29, 2018
Messages
17
Hello all. So I have some code that splits up a string and pastes certain parts of the string into certain columns. It works fine if you just run it from VBA editor. But it would be a nice touch if you added it to the right click mouse menu. I have some other code (not included) that works fine when I added this right click feature. This bit of code, Splitter(), ceases to function and gives the error message of "Wrong Number Of Arguments or invalid property assignment". I noticed if I commented out the right click feature that calls Splitter() the code will run properly again...I apologize for the length of code I know I can write variable declarations in a shorter form, and will do so after I get all the little parts of my program to work. Any advice would be appreciated.

Code:
'Located on sheet 1

[FONT=Verdana]Sub Splitter()[/FONT]
[FONT=Verdana]Dim r As Range
Dim s As String
Dim arr() As String
Dim arr1() As String
Dim arr2() As String
Dim v As Variant
Dim v0 As String
Dim v1 As String
Dim v2 As String
Dim v3 As String
Dim v4 As String
Dim v5 As String
Dim v6 As String
Dim v7 As String
Dim v8 As String
Dim v9 As String
Dim v10 As String
Dim v11 As String
Dim InBox As String[/FONT]
[FONT=Verdana]Dim Prd As Long
Dim Prd1 As Long
Dim First As Long
Range("B1").Select
InBox = InputBox("Please Enter Sap or MOC Number")
If InBox = vbNullString Then Exit Sub[/FONT]
[FONT=Verdana]
Do Until ActiveCell = ""[/FONT]
[FONT=Verdana]s = ActiveCell.Value
First = InStr(1, s, "_")
v10 = Left(s, First - 1)
arr = Split(s, "-")  'Code Breaks here and gives error message[/FONT]
[FONT=Verdana]v1 = arr(1)
v2 = arr(2)
v3 = arr(3)
v4 = arr(4)
arr1 = Split(v4, "_") 'I assume it will break here to....[/FONT]
[FONT=Verdana]v5 = arr1(0)
v6 = arr1(1)
arr2() = Split(v6, ".")
Prd1 = InStr(1, arr2(0), "R")
v7 = Mid(arr2(0), Prd1 + 1)[/FONT]
[FONT=Verdana]v8 = Right(v1, 2)
v9 = Left(v1, 2)[/FONT]
[FONT=Verdana]ActiveCell.Offset(0, 1).Value = v10
ActiveCell.Offset(0, 4).Value = InBox & ":07 Engineering:07.15" _
& "Miscellaneous Engineering Records:07.15.02 Demolition Records"
ActiveCell.Offset(0, 8).Value = "'" & v8
ActiveCell.Offset(0, 9).Value = v2
ActiveCell.Offset(0, 11).Value = v3
ActiveCell.Offset(0, 12).Value = v5
ActiveCell.Offset(0, 13).Value = v10
ActiveCell.Offset(0, 17).Value = v7
ActiveCell.Offset(0, 7).Value = v9
ActiveCell.Offset(0, 7).Value = "Issued for Demolition"
Erase arr()
Erase arr1()
Erase arr2()[/FONT]
[FONT=Verdana]ActiveCell.Offset(1, 0).Select[/FONT]
[FONT=Verdana]Loop[/FONT]
[FONT=Verdana]End Sub
[/FONT]
<strike></strike>


This is part of the code that allows a user to right click to run macro.

Rich (BB code):
'located in Module 1

Sub FileNames()
Call Sheet1.GetNumbers
End Sub

Sub Split() 'If I comment this subroutine, Splitter() can be successfully executed in VBA editor
Call Sheet1.Splitter
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Code:
Dim arr() As Variant
Dim arr1() As Variant
Dim arr2() As Variant
U also seem to have missed v1 = arr(0)?
Anyways, HTH. Dave
 
Upvote 0
Ah that did not do it. It has something to do with trying to run the macro from right clicking mouse. The string stored in arr(0) is not needed so I just leave it out. Thanks any how Dave.
 
Upvote 0
Maybe move the sub to a module and just Call Splitter. U will need to add some code to specify that the sub refer to sheet 1 ie.
Code:
Sheets("Sheet1").Range("B1").Select
Might be worth a trial. Dave
 
Upvote 0
Change the name of this Sub
Code:
[FONT=Verdana][FONT=Verdana]Sub Split() 'If I comment this subroutine, Splitter() can be successfully executed in VBA editor[/FONT]
[FONT=Verdana]Call Sheet1.Splitter[/FONT]
[FONT=Verdana]End Sub[/FONT][/FONT]
You should never use VBA keywords for Subs or variables.
 
Upvote 0
You can put the strin with which you have a problem.


The code works for me, with the right button, with this string:
"abc-def-gh-ij-k_lmnR.opq-rst"
 
Upvote 0

Forum statistics

Threads
1,223,703
Messages
6,173,972
Members
452,540
Latest member
haasro02

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