LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default union range problem

This function finds and selects cells containing the word "Project" (adapted
from post by Jim Tomlinson- Thanks!). The last 4 lines are just for
debugging. All the correct cells are selected as desired (10 cells out of
about 900. All good so far. When Excel selects the cells in the unionized
range, it selects the right cells, but the cell addresses do not match the
cells that are selected. For example, I can see taht the selected cells are
{B33, B42, B67, B73, B129, B149, B403...}, but the debug printout of cell
addresses is {B41, B42, B43, B44, ... B50, B51}. This is the first time I've
used Union(). What am I doing wrong?

Private Function AllPrjCells() As Range
Dim rngSearch As Range
Dim rngFound As Range
Dim rngFirstOccurance As Range
Dim rngPrj As Range
Dim i As Integer

Set rngSearch = Sheets(1).Range("B2:B900")
Set rngFound = rngSearch.Find(what:="Project", Lookat:=xlPart)

If Not rngFound Is Nothing Then
Set rngFirstOccurance = rngFound
Set rngPrj = rngFound
Do
Set rngFound = rngSearch.FindNext(rngFound)
Set rngPrj = Union(rngPrj, rngFound)
Loop Until rngFound.Address = rngFirstOccurance.Address
End If
Set AllPrjCells = rngPrj
AllPrjCells.Select
For i = 0 To AllPrjCells.Cells.Count
Debug.Print AllPrjCells.Cells(i).Address
Next
End Function
 
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
union range Curt Excel Discussion (Misc queries) 9 April 20th 07 02:32 PM
Union/Range/Cells KentÄ[_3_] Excel Programming 2 March 11th 05 11:14 AM
Union method for Range Object Chad Excel Programming 5 March 10th 05 08:02 PM
union problem tom taol Excel Programming 2 February 1st 05 08:43 AM
Excel's range Union operator in WORKDAY function gives #VALUE!. Rod Morrell Excel Programming 0 October 9th 03 02:59 PM


All times are GMT +1. The time now is 07:25 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"