Wrong number of arguments or invalid property assignment

guiltyberto

New Member
Joined
Jul 22, 2014
Messages
23
What does this error mean and how can i fix it?

Code:
Set wb = Workbooks.Open(filename, True, True)

Do While Range("C" & i).Value <> ""
    Dim newChart As Chart
    Dim accName As String
    
    Set newChart = Charts.Add
    accName = Range("C" & i).Value
    
    MsgBox ("Got here")
    
    With newChart
        .ChartType = xlColumnClustered
        
        '.Location Where:=xlLocationAsObject, Name:="Accounts Chart"
        
        .SeriesCollection.NewSeries
        .SeriesCollection((i - 2) / 6).Name = accName
        MsgBox ("Got here 1")
        .Legend.Delete
        MsgBox ("Got here 2")
        .SeriesCollection((i - 2) / 6).Values = wb.Worksheets("Summary-Account").Range("E" & i & ":G" & i, "I" & i & ":K" & i, "M" & i & ":O" & i, "Q" & i & ":S" & i) 'error here
        MsgBox ("Got here 3")
        .SeriesCollection((i - 2) / 6).XValues = wb.Worksheets("Summary-Account").Range("E3:G3, I3:K3, M3:O3, Q3:S3")
        .HasTitle = True
        .ChartTitle.Text = accName
        MsgBox ("got here 3")
    End With
    
    i = i + 5
    
Loop

Thanks!!
 
Last edited:

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Code:
[COLOR=#333333].SeriesCollection((i - 2) / 6).Values = wb.Worksheets("Summary-Account").Range("E" & i & ":G" & i, "I" & i & ":K" & i, "M" & i & ":O" & i, "Q" & i & ":S" & i) 'error here

Right under MsgBox("Got here 2")

Sorry for the confusion[/COLOR]
 
Upvote 0
Can you tell us what the following outputs before the error occurs (insert before error line)

msgbox "E" & i & ":G" & i, "I" & i & ":K" & i, "M" & i & ":O" & i, "Q" & i & ":S" & i
msgbox (i-2)/6
 
Upvote 0
When i is odd you can't get an integer value for the .SeriesCollection index, and with i accumulating by 5 each loop it will be odd every second loop.
 
Upvote 0
Code:
MsgBox ("E" & i & ":G" & i & ", " & "I" & i & ":K" & i & ", " & "M" & i & ":O" & i & ", " & "Q" & i & ":S" & i)
*Note: this code was edited and the commas added in, idk if its supposed to be .Range("string", "string", "string") or .Range("string, string, string") for the range function to work

eg .Range("E8:G8", "I8:K8", "M8:O8", "Q8:S8") vs .Range("E8:G8, I8:K8, M8:O8, Q8:S8")

yielded "E8:G8, I8:K8, M8:O8, Q8:S8"

Code:
MsgBox ((i - 2) / 6 & "")

yielded "1"
 
Last edited:
Upvote 0
The Range function as you are using it should be passed a single string with the comma's included in it. If you use a comma outside a string then the Range is expecting only 2 Arguments, both Range objects, to set the corners of a block Range.
 
Upvote 0
The Range function as you are using it should be passed a single string with the comma's included in it. If you use a comma outside a string then the Range is expecting only 2 Arguments, both Range objects, to set the corners of a block Range.

Worked perfectly, thank you so much!
 
Upvote 0

Forum statistics

Threads
1,215,425
Messages
6,124,825
Members
449,190
Latest member
rscraig11

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