PC Review


Reply
Thread Tools Rate Thread

Add non-contiguous cells to range?

 
 
Ed
Guest
Posts: n/a
 
      27th Mar 2007
A worksheet has one column of invoice numbers. The invoice number is
repeated in contiguous rows for each item in listed on that invoice.
The column to the left has text in some cells. Right now I am
grabbing the invoice number from another sheet, using Find to set an
initial range to the first cell in the column with that number, and
then using the loop code below to extend the range to include all the
cells with that same number.

Do
If rngWork.Offset(1, 0).Text = strInvNo Then
Set rngWork = Union(rngWork, rngWork.Offset(1, 0))
Else
Exit Do
End If
Loop

What I would like to do, but can't figure out how, is to check the
cell to the left for text: if text is present, do NOT add the cell to
the range. Something like:

Do
If rngWork.Offset(1, 0).Text = strInvNo And _
rngWork.Offsset(1,1).Text = "" Then
ADD rngWork.Offset(1, 0) TO RNGWORK
Else
Exit Do
End If
Loop

Union and Intersect I know. But how to I add a non-contiguous cell to
a range?

Ed

 
Reply With Quote
 
 
 
 
John Green
Guest
Posts: n/a
 
      27th Mar 2007
Ed,

Union can be used to create a non-contiguous range, but you will need to
change the way you track the data you are testing. Assuming that rngWork
starts out as a single starting cell (and you mean the cell to the right has
the text), you could use something like the following:

Set rngStart = rngWork

lRow = 1

Do While rngStart.Text = rngStart.Offset(lRow, 0).Text

If rngStart.Offset(lRow, 1).Text = "" Then
Set rngWork = Union(rngWork, rngStart.Offset(lRow, 0))
End If

lRow = lRow + 1

Loop

John Green

"Ed" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>A worksheet has one column of invoice numbers. The invoice number is
> repeated in contiguous rows for each item in listed on that invoice.
> The column to the left has text in some cells. Right now I am
> grabbing the invoice number from another sheet, using Find to set an
> initial range to the first cell in the column with that number, and
> then using the loop code below to extend the range to include all the
> cells with that same number.
>
> Do
> If rngWork.Offset(1, 0).Text = strInvNo Then
> Set rngWork = Union(rngWork, rngWork.Offset(1, 0))
> Else
> Exit Do
> End If
> Loop
>
> What I would like to do, but can't figure out how, is to check the
> cell to the left for text: if text is present, do NOT add the cell to
> the range. Something like:
>
> Do
> If rngWork.Offset(1, 0).Text = strInvNo And _
> rngWork.Offsset(1,1).Text = "" Then
> ADD rngWork.Offset(1, 0) TO RNGWORK
> Else
> Exit Do
> End If
> Loop
>
> Union and Intersect I know. But how to I add a non-contiguous cell to
> a range?
>
> Ed
>



 
Reply With Quote
 
Ed
Guest
Posts: n/a
 
      27th Mar 2007
John: Thanks so much! It worked great! Every time I tried Union
before, I would wind up with everything. This, though, did exclude
the cells with text.

Thanks for the boost.
Ed


On Mar 26, 5:56 pm, "John Green" <greenj@nospam> wrote:
> Ed,
>
> Union can be used to create a non-contiguous range, but you will need to
> change the way you track the data you are testing. Assuming that rngWork
> starts out as a single starting cell (and you mean the cell to the right has
> the text), you could use something like the following:
>
> Set rngStart = rngWork
>
> lRow = 1
>
> Do While rngStart.Text = rngStart.Offset(lRow, 0).Text
>
> If rngStart.Offset(lRow, 1).Text = "" Then
> Set rngWork = Union(rngWork, rngStart.Offset(lRow, 0))
> End If
>
> lRow = lRow + 1
>
> Loop
>
> John Green
>
> "Ed" <prof_ofw...@yahoo.com> wrote in message
>
> news:(E-Mail Removed)...
>
>
>
> >A worksheet has one column of invoice numbers. The invoice number is
> > repeated in contiguous rows for each item in listed on that invoice.
> > The column to the left has text in some cells. Right now I am
> > grabbing the invoice number from another sheet, using Find to set an
> > initial range to the first cell in the column with that number, and
> > then using the loop code below to extend the range to include all the
> > cells with that same number.

>
> > Do
> > If rngWork.Offset(1, 0).Text = strInvNo Then
> > Set rngWork = Union(rngWork, rngWork.Offset(1, 0))
> > Else
> > Exit Do
> > End If
> > Loop

>
> > What I would like to do, but can't figure out how, is to check the
> > cell to the left for text: if text is present, do NOT add the cell to
> > the range. Something like:

>
> > Do
> > If rngWork.Offset(1, 0).Text = strInvNo And _
> > rngWork.Offsset(1,1).Text = "" Then
> > ADD rngWork.Offset(1, 0) TO RNGWORK
> > Else
> > Exit Do
> > End If
> > Loop

>
> > Union and Intersect I know. But how to I add a non-contiguous cell to
> > a range?

>
> > Ed- Hide quoted text -

>
> - Show quoted text -



 
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
Resize range of non-contiguous cells Paul Martin Microsoft Excel Programming 7 10th Jul 2009 01:13 AM
shorthand for consistent but non-contiguous range of cells Julz Microsoft Excel Discussion 2 18th Nov 2007 09:16 PM
Range and non contiguous cells =?Utf-8?B?ZnNtZWxnYXI=?= Microsoft Excel Programming 3 15th Jun 2007 08:44 PM
counting cells that are >0 in a range of non-contiguous cells =?Utf-8?B?TWFyaw==?= Microsoft Excel Worksheet Functions 9 14th Mar 2007 02:45 PM
Range holding non-contiguous cells William Benson Microsoft Excel Programming 24 27th Jul 2005 02:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:54 AM.