Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default iterate columns to select certain cells

All,

I have the following to select a range of cells in a column from A2 thru the
last row in the sheet.

Range("A2:A" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select

How can I select the very same set of cells but iterate to each of the
columns in turn. I can't figure out how to go to column B,C,D and on. I've
got

Columns.Next.Select

but can't select the cells that were selected in the previous. All it
selects is the first cell.

Help

Dale Jones


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default iterate columns to select certain cells

Hei Dale

Range("A2:A" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select
Range("B2:B" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select
Range("c2:c" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select

regards Yngve

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default iterate columns to select certain cells

Thanx for the reply Yngve.

The problem is, as I should have stated, is I don't know waht the final
number of columns will be. That will not be static.

Any ideas?

Dale


"Yngve" wrote in message
oups.com...
Hei Dale

Range("A2:A" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select
Range("B2:B" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select
Range("c2:c" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select

regards Yngve



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default iterate columns to select certain cells

I'm not sure...

dim LastRow as long
dim LastCol as long
dim iRow as long
dim iCol as long

with activesheet
lastrow = .Cells.SpecialCells(xlCellTypeLastCell).Row
lastcol = .Cells.SpecialCells(xlCellTypeLastCell).Column

for icol = 1 to lastcol
for irow = 1 to lastrow
msgbox .cells(irow,icol).value
next irow
next icol
end with




Dale wrote:

All,

I have the following to select a range of cells in a column from A2 thru the
last row in the sheet.

Range("A2:A" &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select

How can I select the very same set of cells but iterate to each of the
columns in turn. I can't figure out how to go to column B,C,D and on. I've
got

Columns.Next.Select

but can't select the cells that were selected in the previous. All it
selects is the first cell.

Help

Dale Jones


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default iterate columns to select certain cells

hei Dale

try this

Sub DynColNr()
Dim Lc As Long
Dim j As Long
Dim kol As String
' count columns (and change "Ark1" to your sheet name)
Lc = Sheets("Ark1").Range("IV1").End(xlToLeft).Column

For j = 1 To Lc
kol = ColumnLtr(j)
Range(kol & "2:" & kol &
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Row).Select
' do things here.
Next j
'MsgBox kol
End Sub

Public Function ColumnLtr(ByVal Column_Number As Long) As String


'Converts a number to a Column Letter
'Leith Ross


Dim Ltr As String
Dim N1 As Long
Dim N2 As Long

'Column must greater than 0
Column_Number = Column_Number - 1
If Column_Number < 0 Then
ColumnLtr = ""
Exit Function
End If


'Maximum Column value is 256
If Column_Number 256 Then Column_Number = Column_Number Mod 256


'Convert to Column_Number Base 26
N1 = Column_Number \ 26
N2 = Column_Number Mod 26


'Convert number to Alpha characters
If N1 = 0 Then
Ltr = ""
Else
Ltr = Chr$(64 + N1)
End If


Ltr = Ltr & Chr$(65 + N2)


ColumnLtr = Ltr


End Function

regards Yngve

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Set MyRange for non-adjacent cells and iterate through? Ed Excel Programming 2 January 3rd 06 06:13 PM
How To Iterate a range of cells? StarGazerNC Excel Programming 5 August 4th 04 04:51 PM
select only certain cells in a columns desperate Excel Programming 5 March 2nd 04 06:51 PM
Iterate columns wired Excel Programming 9 November 14th 03 11:14 PM


All times are GMT +1. The time now is 08:59 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"