Cells VBA Function

JJJ55

New Member
Joined
Jul 31, 2015
Messages
5
I have just got a new version of excel and the cells property in VBA no longer works and I am shown the following error message. "Wrong number of arguments or invalid property assignment".

This happens even when writing the simplest code.

Are there settings that need to be changed?
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
post your code.
I use 2010 and Cells( ) works fine. it would not have been altered as backward compatibility would be lost.
 
Upvote 0
Here is the simple code I am trying to run

For i = 1 To 100
Cells(i, 1).Value = i ^ 2
Next
 
Upvote 0
it is better programming to tell vba which sheet you are writing to, as vba runs on the active sheet, so if for some reason you are not on the right sheet, you will get strange results. assuming you are on sheet1:

Code:
    For i = 1 To 100
        Sheets("Sheet1").Cells(i, 1).Value = i ^ 2
    Next I     <-----------note the I on the end

PS if you are new to coding, can I encourage you to use meaningful variable names. it will help when your code is lengthy and you are revisiting it in 12 months time :)
 
Upvote 0
Your Quote: "I have just got a new version of excel "
What version of Excel did you just get?
 
Upvote 0
Thanks. So do you always have to declare sheet when using the cells property? When previously doing so, I don't remember having to do so.
 
Upvote 0
Your simple script ran OK on my computer using Excel 2013. That's why I asked what new version you are using.
Thanks. So do you always have to declare sheet when using the cells property? When previously doing so, I don't remember having to do so.
 
Upvote 0
if you never change the sheet you are looking at, then you wont notice anything. but it is good programming practise and I always do it.
if you are doing a lot with cells in a sub you like do this...

Code:
    With Sheets("MySheet")
        .cells(1,5)= 5 * .cells(3,7)
        .range("A5") = "hello"
    End With
 
Upvote 0
It is also 2013. Previously had 07 and never had issues with running the Cells property, without declaring the sheet.
 
Upvote 0
No I never declare sheet names if it's for the active sheet and I don't normally use the Next i unless I'm using several next statements just to keep me from getting confused.
It is also 2013. Previously had 07 and never had issues with running the Cells property, without declaring the sheet.
 
Upvote 0

Forum statistics

Threads
1,215,444
Messages
6,124,893
Members
449,194
Latest member
JayEggleton

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