PC Review


Reply
Thread Tools Rate Thread

Columns collection Address

 
 
=?Utf-8?B?VmxhZG8gU3ZlZGE=?=
Guest
Posts: n/a
 
      14th Feb 2007
I'm searching the simplest way how to address uncontinuos (sub)range of
columns.
Imagine that you want to do something with columns 4 (= "D"), 7 (= "G"), 8
(= "H") and 12 (="L"). I'm trying to find something like:
For Each MyCell In MyRange.Columns(4, 7, 8, 12).Cells
..... do something
Next MyCell

So my question is, how to address Columns(4, 7, 8, 12) by the simplest way.

I welcome every good idea.

Vlado
 
Reply With Quote
 
 
 
 
paul.robinson@it-tallaght.ie
Guest
Posts: n/a
 
      14th Feb 2007
On Feb 14, 12:43 pm, Vlado Sveda
<VladoSv...@discussions.microsoft.com> wrote:
Hi
You could do
Dim ColumnsToCount(1 to 4) as long
ColumnsTocount(1) = 4
ColumnsTocount(2) = 7
ColumnsTocount(3) = 8
ColumnsTocount(4) = 12
RowsToCount = MyRange.Rows.Count
For i = 1 to RowsToCount

> I'm searching the simplest way how to address uncontinuos (sub)range of
> columns.
> Imagine that you want to do something with columns 4 (= "D"), 7 (= "G"), 8
> (= "H") and 12 (="L"). I'm trying to find something like:
> For Each MyCell In MyRange.Columns(4, 7, 8, 12).Cells
> ..... do something
> Next MyCell
>
> So my question is, how to address Columns(4, 7, 8, 12) by the simplest way.
>
> I welcome every good idea.
>
> Vlado



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      14th Feb 2007
Dim cell As Range
For Each cell In Range("D1,G1,H1,L1").EntireColumn.Cells
MsgBox cell.Address
Next cell


--
HTH

Bob Phillips

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"Vlado Sveda" <(E-Mail Removed)> wrote in message
news:B2AA3CD6-278A-4C64-9B70-(E-Mail Removed)...
> I'm searching the simplest way how to address uncontinuos (sub)range of
> columns.
> Imagine that you want to do something with columns 4 (= "D"), 7 (= "G"), 8
> (= "H") and 12 (="L"). I'm trying to find something like:
> For Each MyCell In MyRange.Columns(4, 7, 8, 12).Cells
> ..... do something
> Next MyCell
>
> So my question is, how to address Columns(4, 7, 8, 12) by the simplest

way.
>
> I welcome every good idea.
>
> Vlado



 
Reply With Quote
 
=?Utf-8?B?VmxhZG8gU3ZlZGE=?=
Guest
Posts: n/a
 
      14th Feb 2007
Thanks Paul,
but it isn't what I was looking for.

Meanwhile I came up with this solution:

Set MyRange = ActiveSheet.Cells(FIRST_ROW, FIRST_COLUMN).CurrentRegion

Set MyRange2 = Application.Union(MyRange.Columns(4), _
MyRange.Columns(7), _
MyRange.Columns(8), _
MyRange.Columns(12))
For Each MyCell In MyRange2.Cells
..... do something
Next MyCell

Nevertheless thank you for your help

Vlado




"(E-Mail Removed)" wrote:

> On Feb 14, 12:43 pm, Vlado Sveda
> <VladoSv...@discussions.microsoft.com> wrote:
> Hi
> You could do
> Dim ColumnsToCount(1 to 4) as long
> ColumnsTocount(1) = 4
> ColumnsTocount(2) = 7
> ColumnsTocount(3) = 8
> ColumnsTocount(4) = 12
> RowsToCount = MyRange.Rows.Count
> For i = 1 to RowsToCount
>
> > I'm searching the simplest way how to address uncontinuos (sub)range of
> > columns.
> > Imagine that you want to do something with columns 4 (= "D"), 7 (= "G"), 8
> > (= "H") and 12 (="L"). I'm trying to find something like:
> > For Each MyCell In MyRange.Columns(4, 7, 8, 12).Cells
> > ..... do something
> > Next MyCell
> >
> > So my question is, how to address Columns(4, 7, 8, 12) by the simplest way.
> >
> > I welcome every good idea.
> >
> > Vlado

>
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      14th Feb 2007
And building on Bob's response, maybe...

Dim cell As Range
dim myCols as range
dim myRange as range

Set myrange = somethinggoeshere

set mycols = nothing
on error resume next
set mycols = intersect(myrange, _
myrange.parent.Range("D1,G1,H1,L1").EntireColumn.Cells)
on error goto 0

if mycols is nothing then
msgbox "no cols!
'exit sub '???
else
for eacy cell in mycols.cells
MsgBox cell.Address
Next cell
end if

Vlado Sveda wrote:
>
> I'm searching the simplest way how to address uncontinuos (sub)range of
> columns.
> Imagine that you want to do something with columns 4 (= "D"), 7 (= "G"), 8
> (= "H") and 12 (="L"). I'm trying to find something like:
> For Each MyCell In MyRange.Columns(4, 7, 8, 12).Cells
> ..... do something
> Next MyCell
>
> So my question is, how to address Columns(4, 7, 8, 12) by the simplest way.
>
> I welcome every good idea.
>
> Vlado


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?VmxhZG8gU3ZlZGE=?=
Guest
Posts: n/a
 
      14th Feb 2007
I solved my problem as you can see up.

Thank to all !
Vlado
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft ASP .NET 1 18th May 2007 10:24 AM
Collection problems (create Collection object, add data to collection, bind collection to datagrid) Øyvind Isaksen Microsoft Dot NET 1 18th May 2007 10:24 AM
DataTable columns collection mercercreek Microsoft ASP .NET 2 26th Dec 2006 10:03 PM
excel columns collection? Ron Microsoft Excel Programming 3 5th Apr 2005 09:23 PM
More columns than I asked for in columns collection Douglas Buchanan Microsoft ADO .NET 4 30th Oct 2004 04:16 AM


Features
 

Advertising
 

Newsgroups
 


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