PDA

View Full Version : Excel 2007 Vba Question



kenny123
10-11-2011, 08:11 PM
"Microsoft Listview Control 6.0" can edit cells as worksheet
or only for a view?

"Microsoft Listview Control 6.0" can set title names,but "Microsoft Spreadsheet Control 11.0" can't do these?

I found error in the following code which set in UserForm_Initialize, i don't know why.(userform already with Spreadsheet1)

Private Sub UserForm_Initialize()
...
With Spreadsheet1
.ActiveSheet.Range(Cells(1, 1), Cells(2, 2)).Interior.ColorIndex = 3
End With
...
end sub

But the code can run in worksheet.
sub XXX()
ActiveSheet.Range(Cells(1, 1), Cells(2, 2)).Interior.ColorIndex = 3
end sub :dunno

Stargazer
10-12-2011, 02:07 AM
Instead of saying using a with, just do a straight "Sheet1.Range("Blah blah")......" and so on.

Cleaner, tidier and more direct.

Rob.

Aflatoon
10-12-2011, 05:06 AM
You have not qualified the Cells properties in either case, which is incorrect:
Private Sub UserForm_Initialize()
...
With Spreadsheet1.ActiveSheet
.Range(.Cells(1, 1), .Cells(2, 2)).Interior.ColorIndex = 3
End With
...
End Sub

I would respectfully disagree with the comment about tidiness.

Bob Phillips
10-12-2011, 05:36 AM
I would respectfully disagree with the comment about tidiness.

Well it was right if there hadn't been the other unqualified references :*)

Aflatoon
10-12-2011, 05:52 AM
I will accept that - I am often 'right under different circumstances'. :)

Bob Phillips
10-12-2011, 06:02 AM
I am often 'right under different circumstances'. :)

I think you can do better than that and say ... I am always 'right under different circumstances'. :devil2:

Aflatoon
10-12-2011, 06:21 AM
Ah, but I am sometimes, I think, right under the current circumstances, rather than different ones. Perhaps a generic "I am right under appropriate conditions"?

Aussiebear
10-12-2011, 03:33 PM
Ah, but I am sometimes, I think, right under the current circumstances, rather than different ones. Perhaps a generic "I am right under appropriate conditions"?

Well I thunk you is rite this time bro