Delete columns based on cell value

Billdub417

New Member
Joined
Nov 5, 2019
Messages
45
Hello,

I have a formula in cell a1 of a sheet which results in a number between 6 and 28

Based on this value, is it possible to create a vba that would select this column and those beyond it, i.e. if it said 8, it would select columns H : XFD and delete the columns?

Appreciate any help,

VMT.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
How about
VBA Code:
Sub Billdub()
   Range(Cells(1, Cells(1, 1)), Cells(1, Columns.Count)).EntireColumn.Delete
End Sub
 
Upvote 0
thankyou!

Is it possible to adapt the same code to copy all previous columns? i.e. in the above example, it would copy columns A:G?
 
Upvote 0
How about
VBA Code:
Sub Billdub()
   Range("A1", Cells(1, Cells(1, 1) - 1)).EntireColumn.Copy
End Sub
 
Upvote 0
Solution
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,189
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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