Reputation: 27
For some reason I can't figure out how to do this... it seems so basic:
Trying to delete unwanted columns starting at a specific row.
Example: Want to delete Columns C, D, E, M, N and L all starting at row 10 of Wsh2.
'deleting columns that are unwanted
Cells(wsh2.Cells("C10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("D10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("E10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("M10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("N10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
Cells(wsh2.Cells("L10"), wsh2.Cells("C10").End(xlDown)).EntireColumn.Delete
End Sub
I've adapted a previous code that I found on here that used Range. I've also attempted using Union and Range but cant seem to figure it out.
Basically: Trying to delete only specific columns starting at a particular row after I've copied a range of rows from a previous worksheet.
Any help would be great. Thank you!
Upvotes: 0
Views: 4494
Reputation: 729
You do not actually want to delete the entire column, as you stated. You want to clear cells C10:Cend
, D10:Dend
, E10:Eend
, M10:Mend
, N10:Nend
, and L10:Lend
. This is what you want to have your code do. Navigate to the cell of choice, and clear all cells below that specific coordinate.
For ease, you could just loop through all cells from C10
to C10000
and delete the contents of each cell, for example, which would be very simple to implement, though potentially not the most efficient.
Upvotes: 0
Reputation: 1017
if you use EntireColumn.Delete it will delete the entire column, you need to get the range and delete that instead, eg.
Range("C10:C" & Rows.Count).Delete
Upvotes: 2