VBA - Select Multiple Columns using Column Number

Cosmos75

Active Member
Joined
Feb 28, 2002
Messages
359
Is there a way to select multiple columns in VBA using the column number?

I have this
Code:
Range("D:E,G:H,J:K,M:N").Select
Selection.Delete Shift:=xlToLeft
But I would prefer to be able to select those columns using column numbers. It will not always be the same columns so using column numbers would be easier for me to code.
 
Dear Sir @Peter_SSs,

Can you help for loop approach which can apply to access/process noncontiguous columns
Based on column number?

I have one doubt that .Entire column can be use
To process columns of perticular range? Or it will
Process whole column of sheet?

May be I think with the help of Array of comumn number ..but how ,?

Please help.

Regards,

Chirag Raval
 
Last edited:
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Code:
Sub ColsByNumber()
  Dim LastRow As Long, i As Long
  Dim aCols As Variant
  
  aCols = Split("1 4 5 8")
  LastRow = Range("A" & Rows.Count).End(xlUp).Row
  For i = 0 To UBound(aCols)
    With Columns(CLng(aCols(i))).Resize(LastRow)
      .Font.Bold = True
    End With
  Next i
End Sub
 
Upvote 0
Dear Sir @Peter_SSs,

Yes, Amazing, work like a charm...Really very helpful forever..

Array , split based on simple space is really acceptable & new concept. really great,

And I study Clng function on here that also very helpful.

https://www.techonthenet.com/excel/formulas/clng.php

That's also very useful to understand.

Thank you very much sir for your kind help.

Regards,

Chirag Raval
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,155
Messages
6,123,335
Members
449,098
Latest member
thnirmitha

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