Clear Columns from "F" to the Very End

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Code:
Columns("F:XFD").Select
Selection.Clear

Hello All,
The code above is working to clear all the cells. However, I would like to use another way instead of just referring to Column XFD to find the very end column.
Is there another way to select all columns from "F:to the end" and instead of clearing, just simply delete all those columns?
Thanks for the help
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
If you're just going to Delete them anyway, why do you need to find it?

BTW, you rarely need to Select in VBA.
Code:
Sub test()
Range("F:XFD").Delete
End Sub

But if you really want to, can we determine where the end is based on Row 1?

Code:
Sub test()
Range("F:F", Cells(1, Columns.Count).End(xlToLeft).EntireColumn).Delete
End Sub
 
Last edited:
Upvote 0
You can use the reference number of the columns ("A"=1,"B"=2,"C"=3,...) to do it like this:
Code:
    Range(Columns(6), Columns(Columns.Count)).Clear
Note that it is not necessary to select the columns in order to clear them (and selecting them actually slows the code down).
The Macro Recorder is very literal, and records all of the range selections, but many/most can be eliminated to speed up your code.
 
Upvote 0
Code:
Sub test()
Range("F:F", Cells(1, Columns.Count).End(xlToLeft).EntireColumn).Delete
End Sub

This is working well, thank you
 
Upvote 0

Forum statistics

Threads
1,224,737
Messages
6,180,670
Members
452,993
Latest member
FDARYABEE

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