ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Selecting every fourth cell in a coloumn (https://www.excelbanter.com/excel-programming/279483-selecting-every-fourth-cell-coloumn.html)

hke

Selecting every fourth cell in a coloumn
 
Hi all. I would like som help on the following:

Like when using the ctrl key, I want to select several non-adjacent
cells. I want to select every fourth cell in a coloumn with about 1500
cells.

The code below helps me to move the selection down, but it does not
keep the previous selection. Any sugestions?

ActiveCell.Select
For i = 1 To 1500
ActiveCell.Offset(3).Select
i = i + 1
Next



------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/


[email protected]

Selecting every fourth cell in a coloumn
 
You can adapt this to suit your needs.

Sub EveryFourth()
Dim i As Integer
Dim rngR As Range

For i = 1 To 1500
If Not rngR Is Nothing Then
Set rngR = Union(rngR, Cells(i * 4, 1))
Else
Set rngR = Cells(i * 4, 1)
End If
Next i

rngR.Select

End Sub

Tested using Excel 97SR2 on Windows 98SE,

HTH
Paul
--------------------------------------------------------------------------------------------------------------
Be advised to back up your WorkBook before attempting to make changes.
--------------------------------------------------------------------------------------------------------------

Hi all. I would like som help on the following:

Like when using the ctrl key, I want to select several non-adjacent
cells. I want to select every fourth cell in a coloumn with about 1500
cells.

The code below helps me to move the selection down, but it does not
keep the previous selection. Any sugestions?

ActiveCell.Select
For i = 1 To 1500
ActiveCell.Offset(3).Select
i = i + 1
Next



GB[_3_]

Selecting every fourth cell in a coloumn
 

"hke" wrote in message
...
Hi all. I would like som help on the following:

Like when using the ctrl key, I want to select several non-adjacent
cells. I want to select every fourth cell in a coloumn with about 1500
cells.

The code below helps me to move the selection down, but it does not
keep the previous selection. Any sugestions?

ActiveCell.Select
For i = 1 To 1500
ActiveCell.Offset(3).Select
i = i + 1
Next


Try this:

Dim MyRange as Range
Set MyRange=ActiveCell

For i = 1 to 500
ActiveCell.Offset(3).Select
Set MyRange = Union (MyRange, ActiveCell)
Next i

Geoff




------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~ View and post usenet messages directly from http://www.ExcelForum.com/





All times are GMT +1. The time now is 02:37 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com