• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

complie error

sony123

Member
i'm getting compile error and expected array as message while iam running VBA script...

the script is as follows....

Dim Lastrow as Long
Range("A1:A10").Value=10
rowcount=lastrow(sheet1).cells("A"&rows.count).End(x1up).Row
msgbox ("no of rows is" & rowcount)

Note: I can do row count with other syntax but i want to learn with above script...if u can explian detailly would be more appriciate...

Thank you....
 
Hi ,

The problem is in this line :

rowcount=lastrow(sheet1).cells("A"&rows.count).End(x1up).Row

The highlighted character should be an l ( the letter L ) and not the digit 1.

Narayan
 
Hi ,

I think you should post the complete code rather than put out bits and pieces.

The problem is still in the same line :

rowcount=lastrow(sheet1).cells("A"&rows.count).End(x1up).Row

I do not know what lastrow(sheet1) does ; can you explain or post the code for the lastrow function ?

The function has been declared as returning a Long result ; the construct :

lastrow(sheet1).cells().End().Row

can be used only if the portion lastrow(sheet1) is a Range object.

Narayan
 
Function LastRow(rng as Range) As Long
Dim iRownN As Long
Dim iRow As Long
Dim Rowcount As Long
Dim i ColN As Integer
Dim i ColI As Integer
i RowN=0
iColN=rng.Columns.Count
For iColI=1To iColN
IRowI=rng.Columns(icolI).Offset(65001-rng.Row,0).End(xlup).Row
If iRowI>iRowN Then iRowN=iRowI
Next
LastRow=iRowN
 
Hi ,

First there is an extra space in the declarations :

Dim i ColN As Integer
Dim i ColI As Integer

It should either be :

Dim iColN As Integer
Dim iColI As Integer

or

Dim i_ColN As Integer
Dim i_ColI As Integer

Narayan
 
Hi ,

It is late at night for me ; I hope someone else pitches in.

It would be better if you upload your file ; 2 hours have been spent in identifying typographical errors !

Narayan
 
Hi, sonny123!
As you were told, consider uploading a sample file (including manual examples of desired output if applicable), it'd be very useful for those who read this and might be able to help you. Thank you.
And if ever posting code, please:
a) Put it into the proper container (penultimate icon in the Reply toolbar)
b) Post the exact and entire code (typo errors, missing lines -at least End Function-)
c) If any compile error, indicate the exact error description and the line where it happens
Regards!
 
Back
Top