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: 35
Default Creating a range name based on cell content not being a negative value.

The following code creates a range name called Cost1 on column F, the
range obviously starts at F2 with it's ending point defined as the last
cell in column F that is not a negative value.
The data in column F is sorted such that all the negative values are at
the bottom (sorted in ascending order) and all values greater than zero
are above the negative values, the positive values are sorted in
ascending order.

Example data
12
56
78
97
101
(59)
(53)
(34)

So long as the data is presented per the above sample the macro works
fine, the named range starts at F2 and ends at the last positive value.

I have 2 questions:-
1. how would you re-write the code assuming that column F is sorted in
desending order.
example:
101
97
78
56
12
(34)
(53)
(59)

2. how would you re-write the code assumng that column F is sorted in
desending order, but then the positive values in column F are in some
random order based on a sort to a different column.
example:
78
12
101
97
56
(34)
(53)
(59)
Sub Tester()

Dim Start As Range
Dim cell As Range
Dim vVal As Variant
Set Start = Range("f2")
vVal = Start.Value
For Each cell In Range(Cells(1, 6), Cells(1, 6).End(xlDown)(2))
If cell.Value < vVal Then
Range(Start, cell.Offset(-1, 0)).Name = "Cost1"
Set Start = cell
vVal = Start.Value
End If
Next

End Sub

burl_h

 
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
Copy row based on cell content billinr New Users to Excel 6 February 21st 07 01:49 PM
how do I change the content of one cell based on another? Barry Excel Discussion (Misc queries) 2 September 3rd 06 10:16 AM
Name range based on Cell content Abdul[_2_] Excel Programming 5 September 2nd 06 12:17 PM
Extracting content based on criteria and creating new workbook Gary J. Dikkema Excel Programming 1 April 17th 06 08:03 PM
Add name by vba based on cell content christobal Excel Programming 3 April 1st 04 12:00 PM


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