Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TO DEFINE AMBIGUOUS RANGE !


In Range("B2:B150") any number of cells can have their font formatted
to bold.The cells may be in succession(contiguous) or may not be in
succession(noncontiguous).

I *need a macro* that will loop through the above range, and define a
new range called myRange which is made of all the cells in
Range("B2:B200") whose font are set to bold.
(i.e) myRange=Range(__,__,__,__,__,...)
Where __,__,... are the cells whose fonts are bold.

Please I will need a macro and any help would be appreciated!
Thanks.
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default TO DEFINE AMBIGUOUS RANGE !

Hi Jay

A variation of John Walkenbach's code at
http://j-walk.com/ss/excel/tips/tip99.htm

Sub SelectBoldCells()
Dim WorkRange As Range
Dim FoundCells As Range
Dim Cell As Range
Set WorkRange = Range("B2:B200")
For Each Cell In WorkRange
If Cell.Font.Bold = True Then
If FoundCells Is Nothing Then
Set FoundCells = Cell
Else
Set FoundCells = Union(FoundCells, Cell)
End If
End If
Next Cell
If FoundCells Is Nothing Then
MsgBox "None."
Else
FoundCells.Select
End If
End Sub

HTH. Best wishes Harald

"jay dean" skrev i melding
...

In Range("B2:B150") any number of cells can have their font formatted
to bold.The cells may be in succession(contiguous) or may not be in
succession(noncontiguous).

I *need a macro* that will loop through the above range, and define a
new range called myRange which is made of all the cells in
Range("B2:B200") whose font are set to bold.
(i.e) myRange=Range(__,__,__,__,__,...)
Where __,__,... are the cells whose fonts are bold.

Please I will need a macro and any help would be appreciated!
Thanks.
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TO DEFINE AMBIGUOUS RANGE !

Harald -
If I want to put the sum formula for FoundCells in cell A1, how would
I do that...
(i.e) Range("A1").formula="=sum(FoundCells)" ?

Thanks
Jay Dean



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default TO DEFINE AMBIGUOUS RANGE !

Maybe one of these:
Range("a1").Value = Application.Sum(FoundCells)

or
Range("a1").Formula = "=sum(" & FoundCells.Address & ")"

But be aware, =sum() has a limit of 30 arguments. If you exceed that limit,
you'll have to do a little more work.

jay dean wrote:

Harald -
If I want to put the sum formula for FoundCells in cell A1, how would
I do that...
(i.e) Range("A1").formula="=sum(FoundCells)" ?

Thanks
Jay Dean

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


--

Dave Peterson

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,327
Default TO DEFINE AMBIGUOUS RANGE !

If that's what you want done -and only that- I'd rewrite it to a function:

Function SumBold(WorkRange As Range) As Double
Dim Cell As Range
Application.Volatile
On Error Resume Next
For Each Cell In WorkRange
If Cell.Font.Bold = True Then _
SumBold = SumBold + Cell.Value
Next Cell
End Function

And in a cell:
=SumBold(B2:B250)

Note that recalculation doesn'a appear whan you change format (like making a
number bold), you must press F9 to get the new result. There is no
workaround for this.

HTH. Best wishes Harald

"jay dean" skrev i melding
...
Harald -
If I want to put the sum formula for FoundCells in cell A1, how would
I do that...
(i.e) Range("A1").formula="=sum(FoundCells)" ?

Thanks
Jay Dean



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 154
Default TO DEFINE AMBIGUOUS RANGE !

Excellent!
Thanks, Harald and Dave.You are the best!!
Jay Dean



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 292
Default TO DEFINE AMBIGUOUS RANGE !

You're welcome Jay Dean.

Best wishes Harald

"jay dean" skrev i melding
...
Excellent!
Thanks, Harald and Dave.You are the best!!
Jay Dean



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



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
Define Name range Gotroots Excel Discussion (Misc queries) 10 December 19th 09 11:30 AM
Define a range jlclyde Excel Discussion (Misc queries) 2 April 17th 08 08:26 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Macro to Define Range Name Phil Excel Programming 6 October 23rd 03 04:00 PM
Define a Range depending on where the EOF is Dag Johansen[_5_] Excel Programming 5 September 23rd 03 03:45 AM


All times are GMT +1. The time now is 12:28 PM.

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"