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
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
804
try
cells(r,5) and cells(r,7)
3
Thanks Venkat, works like a charm.
0
How do you declare r ? Variant? integer? range?
0
Posts
4476
Registration date
Thursday January 28, 2010
Status
Contributor
Last seen
August 2, 2020
768
Long would be the safest. It is being used to handle row numbers.
0
Posts
1864
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
804
[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)
0
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 :)
0