Excel to be the last of me! VB + Excel help needed

Soldato
Joined
18 Oct 2002
Posts
3,074
Location
MK
Thanks for reading this post!

I'm trying to delete a series of rows using a loop to go through a range of cells.
My code works on one sheet, however, when i want to "goto" another sheet it comes up with an error :(

Code:
 Private Sub CommandButton1_Click()
Dim i As Integer
For i = 2 To 6
Sheets("Sheet1").Activate
If ActiveSheet.Cells(i, 1) = "" Then
Sheets("Sheet2").Activate
ActiveSheet.Range(Cells(i, 4), Cells(i, 5)).Select ' ERROR IS ON THIS LINE?
Selection.Clear
End If
Next i
End Sub

Why is this? Or am i missing something?!

Thanks for your help :)
 
I still got the error :(

I am using 2003 excel, mabey thats causing a problem?

I am sure i'm using Excel XP at work, and it dont work there!

I am using this code now, but its a bit slow..

Code:
 Dim i As Integer
Dim j As Integer
Dim x As Integer
 x = 32
For i = 3 To x
	Sheets("Employee").Activate
		If ActiveSheet.Cells(i, 1) = "" Then
		
				Sheets("Jan").Activate
				For j = 4 To x
				ActiveSheet.Cells(i + 1, j).Select
				Selection.ClearContents
				Next j
				
				Sheets("Feb").Activate
				For j = 4 To x
				ActiveSheet.Cells(i + 1, j).Select
				Selection.ClearContents
				Next j

	   'and the same till DEC
				
			 
			   
		End If
Next i
End Sub
 
Back
Top Bottom