Delete certain cells of active row [Solved/Closed]

Report
-
 tatosgr -
Hello,

I would like a code for the following:

Check which row is active/selected and then delete the data which is in the 5th and 7th column of that row.

I've tried the following:

Sub test()
r = ActiveCell.Row
Range(r, 5).ClearContents
Range(r, 7).ClearContents
End Sub

Can someone help me out with this?

Best regards,
Trowa

4 replies

Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
try
cells(r,5) and cells(r,7)
3
Thank you

A few words of thanks would be greatly appreciated. Add comment

CCM 4365 users have said thank you to us this month

Thanks Venkat, works like a charm.
How do you declare r ? Variant? integer? range?
Posts
4475
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
January 6, 2016
756
Long would be the safest. It is being used to handle row numbers.
Posts
1862
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
July 30, 2015
790
[quote]
How do you declare r ? Variant? integer? range?[/quote]

something like this
dim r as range, j as integer, k as long,m(leave it blank then it is variant)
Thanks rizvisa1 and venkat1926 .. I'd try both (waiting for errors or bugs :P) .. If I have any doubt, I'll stop by again :)

Thanks again :)