Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 65
Default Add non-contiguous cells to range?

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Add non-contiguous cells to range?

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" wrote in message
ups.com...
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



  #3   Report Post  
Posted to microsoft.public.excel.programming
Ed Ed is offline
external usenet poster
 
Posts: 65
Default Add non-contiguous cells to range?

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" wrote in message

ups.com...



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
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
Join non-contiguous ranges into one range via named range? ker_01 Excel Discussion (Misc queries) 3 May 1st 09 11:09 AM
counting cells that are 0 in a range of non-contiguous cells Mark Excel Worksheet Functions 9 March 14th 07 02:45 PM
non-contiguous range Stefi Excel Programming 2 October 19th 06 02:38 PM
pasting non-contiguous range of cells to new row, same cell locati Not excelling at macros New Users to Excel 3 April 4th 06 08:57 PM
Range holding non-contiguous cells William Benson[_2_] Excel Programming 24 July 27th 05 02:41 PM


All times are GMT +1. The time now is 05:22 PM.

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

About Us

"It's about Microsoft Excel"