PDA

View Full Version : Help with clear contents



buddy2000
02-12-2011, 11:51 AM
I need to clear contents of the row from "A3" to "D3". This is fixed it will not change.

How ever as the user inputs data I need to clear contents verically and this will change depending on how much data the user inputs. It could be "A3" to "D16" the last cell could be any number.


Here is what I tryed.


Sub Clear()
With Range("A3")
.End(xlToRight).Offset(0, 0).Cells.ClearContents
.End(xlDown).Offset(0, 0).Cells.ClearContents
End With
End Sub



This seems to be close it clears the last cell in one row and it clears the last cell in the first column.

CharlesH
02-12-2011, 01:20 PM
Hi,

See if this works.



Sub Clear()
Range("A3:D" & Range("D65536").End(xlUp).Row).ClearContents
End Sub

buddy2000
02-12-2011, 01:29 PM
Yes it works perfect. However, I do not understand the logic.

Thanks,

CharlesH
02-12-2011, 01:41 PM
HI,

The code looks for the last used cell in column "D" and when you specify the range as I did the code now says "Clear the Contents" in


Range("A3:D and the last used cell in column D")
'So if the last used cell in column D is "16" then the code will
' ClearContents in
Range("A3:D16")



Hope this helps