Click here to Skip to main content
15,907,395 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: (untagged)
I dont use visual basic but i need to select every 4th coloumn of my worksheet .. I need it for some application ... can any one tell me how to do it in visual basic ..
Updated 2-Oct-20 0:28am
Dalek Dave 17-Jun-10 10:35am    
5 rows by 2000 columns is completely the wrong approach to using spreadsheets.

Please think about having 2000 rows of 5 columns, it is more sensible that way.

It is actually very easy, and I will give you the code.
However, before I do I just need to know if the columns are fixed, ie you want columns D, H, L, etc?

If so, something like this...


Should do the trick.
Share this answer
guchu 17-Jun-10 9:13am    
I have data in columns and each column has 5 rows.. I want to select all the rows of every 4th column say A E I ...
guchu 17-Jun-10 9:15am    
and there are 2000 columns like that ...
Here is the code that does the trick,

Sub test1()<br />
<br />
Dim i As Integer<br />
Dim j As Integer<br />
Dim a As Double<br />
<br />
<br />
For i = 1 To 10000        ' counter, from 1 to 672<br />
j = 4 * i - 3             ' steps<br />
Sheets("sheet1").Select 'Sheet you get the data from<br />
Cells(1, j).Select<br />
a = Selection<br />
<br />
Sheets("sheet2").Select 'Sheet you want to copy the date to<br />
Cells(1, i).Value = a<br />
<br />
Next i<br />
<br />
<br />
End Sub
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900