Compile Error: Argument not optional

DiogoCF

New Member
Joined
Jun 8, 2016
Messages
3
Hi everyone,

I am not a pro programer and I am trying to plot a great amount of data and to place the resulting graphs organized at a new sheet. In order to do so, I am making a macro with a simpler data set (image attached). The final purpose is to skip some columns with variable column lengths. My idea was to produce a simple macro, even if it is not the most elegant way to do it. the code is:
Code:
Public Sub chats()


Dim xaxis As Range
Dim yaxis As Range
Dim A As Characters
Dim B As Characters
Dim i As Integer


    For i = 1 To 2
        Dim c As Chart
        Set c = ActiveWorkbook.charts.Add
        Set c = c.Location(Where:=Cells(1, i * 6), Name:="Sheet2")
        With c
            .ChartType = xlXYScatterLines
        End With
        A = MsgBox.Cells(1, 2 * i - 1).Adress(RowAbsolute:=False, ColumnAbsolute:=False)
        B = MsgBox.Cells(1, 2 * i).Adress(RowAbsolute:=False, ColumnAbsolute:=False)
        xaxis = Range(A, Range(A).End(xlDown))
        yaxis = Range(B, Range(B).End(xlDown))
        Dim s As Series
        Set s = c.SeriesCollection.NewSeries
        With s
            .Values = yaxis
            .XValues = xaxis
        End With
        Next i
End Sub
and, when I compile it says that there is a "Compile Error: Argument not optional" right at the beginning and I do not get why...
Thank you for your time and help.
 
Last edited by a moderator:

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Welcome to the forum.

What is MsgBox meant to be in your code? It's a built in VBA function, which is why the compiler is complaining.

Also, you have misspelled Address
 
Last edited:
Upvote 0
Welcome to the forum.

What is MsgBox meant to be in your code? It's a built in VBA function, which is why the compiler is complaining.

Also, you have misspelled Address

Thank you for your reply!

I misspelled "Address" and I have corrected it but it did not solved the problem. I use the MsgBox to convert the coordinates "(1,1)" into "A1", because I see the Range function written everywhere with the "cell name" instead of coordinates. I googled how to do it and this was one of the solutions.
 
Upvote 0
I'm not sure where you found that, but that is not what MsgBox does - it just puts a message up on your screen. The Address property will return the address in A1 format by default:
Code:
        A = Cells(1, 2 * i - 1).Address(RowAbsolute:=False, ColumnAbsolute:=False)
        B = Cells(1, 2 * i).Address(RowAbsolute:=False, ColumnAbsolute:=False)
 
Upvote 0
I'm not sure where you found that, but that is not what MsgBox does - it just puts a message up on your screen. The Address property will return the address in A1 format by default:
Code:
        A = Cells(1, 2 * i - 1).Address(RowAbsolute:=False, ColumnAbsolute:=False)
        B = Cells(1, 2 * i).Address(RowAbsolute:=False, ColumnAbsolute:=False)


Thanks, you are right, of course. Now it is working but it is not doing what was supposed. I think I must change the whole code again, but thank you for your help!
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,327
Members
452,635
Latest member
laura12345

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