How to Delete Cell Contents with VBA

Skippy

Board Regular
Joined
Mar 3, 2002
Messages
194
I have the following VBA code
Code:
Set datRange = Range("D12:D" & Range("D65536").End(xlUp).Row)
numRows = datRange.Rows.Count
It counts the number of cells (rows) in Column D that contains data. Say D12:D20 contain data. What I want to do is then erase the contents (not the entire row) of any cells in Columns E:H from row 21 and down that contain data. The tricky part is that the number of rows in Column D with data will always be changing. Is there a way to add to the code above that will allow me to delete the content of cells in columns adjacent to Col D starting at the point (row) where the cells in Column D are first empty?

Thanks
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Code:
LastRow = Range("D65536").End(xlUp).Row + 1

Range("E" & LastRow & ":H65536").ClearContents
 
Upvote 0
I have the following VBA code
Code:
Set datRange = Range("D12:D" & Range("D65536").End(xlUp).Row)
numRows = datRange.Rows.Count
It counts the number of cells (rows) in Column D that contains data. Say D12:D20 contain data. What I want to do is then erase the contents (not the entire row) of any cells in Columns E:H from row 21 and down that contain data. The tricky part is that the number of rows in Column D with data will always be changing. Is there a way to add to the code above that will allow me to delete the content of cells in columns adjacent to Col D starting at the point (row) where the cells in Column D are first empty?

Thanks

Dear friend,

please find the below code . this useful of " Delete contains data '. then now am using the code for example only.u will be set ur correct range .

sub clear ()
sheet1.cells.range ("D12:D20"). delete true
end sub

this code is delete "D12 to D20" contents
if u want to delete "D" column please use the range ("D")

i hope it is very useful of ur work

Regards,
M.Mohideen Thasthahir
 
Upvote 0
In one line of code...

Code:
Range(Cells(Rows.Count, "D").End(xlUp).Offset(1), Cells(Rows.Count, "D")).Resize(, 5).ClearContents
 
Upvote 0

Forum statistics

Threads
1,214,523
Messages
6,120,030
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top