Any way to make it better?

hitbid

Board Regular
Joined
Jan 21, 2016
Messages
114
Just a quick question,

Since I've been learning arrays I've tried to interject them into places where I can.

For example here, I am deleting certain columns based on their column number, pre-set in an array.

Code:
Dim cols As Variant
Dim counter As Double
Dim Top As Double


cols = Array(8, 5, 3)
Top = UBound(cols)


For counter = 0 To Top
    Columns(cols(counter)).Delete
Next counter

How could this code be even simpler or easier? I just want to learn how to fry a fish differently.
 

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.
You can try this:
Code:
Sub Columns_Delete()
'Modified  7/15/2018  9:03:32 PM  EDT
Range("C1,E1,H1").EntireColumn.Delete
End Sub
 
Upvote 0
maybe:
Code:
Sub Easier()
Range("C:C,E:E,H:H").Delete
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,175
Members
453,021
Latest member
Justyna P

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