qwww
qwww

Reputation: 1363

How to select N columns in excel sheet leaving every kth column unselected?

How can I select N columns in a sheet leaving every kth column unselected? Say I need to select 1000 columns(N) and leave every 10th(K) column free. ie, I need to leave 10,20,30,40 upto 100 unselected.

How can i do it in an easy way?

Upvotes: 0

Views: 66

Answers (1)

shrivallabha.redij
shrivallabha.redij

Reputation: 5902

I am not sure of the purpose. Is it some academic interest?

Something like below shall work:

Dim n As Long, i As Long, stp As Long, q As Long
Dim rG As Range
n = 1000 'Max Columns
q = 10   'Column to skip
i = 1
Set rG = Cells(1, 1)
Do While i < n
    If i Mod q <> 0 Then Set rG = Union(rG, Cells(1, i))
    i = i + 1
Loop
rG.EntireColumn.Select

Upvotes: 2

Related Questions