Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Compile Error - Wrong Number of Arguments or Invalid Property Assignme

Status
Not open for further replies.

tbassngal

Programmer
Feb 18, 2003
74
0
0
US
Hi everyone! When I have just two cells listed to .clear, this works. When I add all the cells I need to be cleared, I get the Compile Error "Wrong Number of Arguments or Invalid Property Assignment" Should I be using something else other than Cells??? Please help!

Sub RemoveStuff()
Dim i As Long
i = 2
While Not IsEmpty(Cells(i, 4))
If Cells(i, 4).Value = Cells(i - 1, 4).Value And Cells(i, 8) <= 0 Then
Range(Cells(i, 19), Cells(i, 20), Cells(i, 21), Cells(i, 22), Cells(i, 23), Cells(i, 24), Cells(i, 25), Cells(i, 26), Cells(i, 27), Cells(i, 28), Cells(i, 29), Cells(i, 30), Cells(i, 31), Cells(i, 32), Cells(i, 33), Cells(i, 34), Cells(i, 35), Cells(i, 36), Cells(i, 37), Cells(i, 38)).Clear
ElseIf Cells(i, 4).Value = Cells(i + 1, 4).Value And Cells(i, 8) <= 0 Then _
Range(Cells(i, 19), Cells(i, 20), Cells(i, 21), Cells(i, 22), Cells(i, 23), Cells(i, 24), Cells(i, 25), Cells(i, 26), Cells(i, 27), Cells(i, 28), Cells(i, 29), Cells(i, 30), Cells(i, 31), Cells(i, 32), Cells(i, 33), Cells(i, 34), Cells(i, 35), Cells(i, 36), Cells(i, 37), Cells(i, 38)).Clear
End If
i = i + 1
Wend
 

Well, you could change it to
Code:
Union(Cells(i, 19), Cells(i, 20), Cells(i, 21), Cells(i, 22), Cells(i, 23), Cells(i, 24), Cells(i, 25), Cells(i, 26), Cells(i, 27), Cells(i, 28), Cells(i, 29), Cells(i, 30), Cells(i, 31), Cells(i, 32), Cells(i, 33), Cells(i, 34), Cells(i, 35), Cells(i, 36), Cells(i, 37), Cells(i, 38)).Clear
But this works just as well and is a bit simpler
Code:
Range(Cells(1, 19), Cells(1, 38)).Clear
 
It worked great, thank you! I've not used cells so much - I didn't realize I could use only the starting and end point instead of listing all the cells. Thank you thank you!!!

Tina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top