View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Carol G Carol G is offline
external usenet poster
 
Posts: 4
Default Re-Naming a column

Jay,
I had wished to apply the name to the whole columns that the tally's are in
but maybe just the cells that I have the totals in. I thought I could work
my way up from the cell I was in and name whole column. I am going to be
pie charting the results but I only need them named so that I know which
are which.
I'll work with it today.
Thanks for your help.
Carol
"Jay" wrote in message
...
Hi Carol -

I'm still a bit unclear about the exact cells that you want to name, but
here's a stab at a starting point. It will apply a name to each of the 5
cells containing a tally. If you want each name to be applied to a larger
group of cells (a whole or part of a column as you mentioned), we'll have

to
modify a bit.

1. Suggested starting point for the left side of the assignment statement:

wholeRange.End(xlToRight).Name =

2. Right side issues: Your suggestion was 'Name(intI).Value'. First,

the
word "Name" is reserved in VBA for the Name property, so change it to
something else (here I used 'rngName'). Second, the Name property (on the
left side) requires that the actual name (on the right side) be passed

with
quotes. For example,

wholeRange.End(xlToRight).Name = "< -15000" is correct when using a
string constant ("<-15000").

So, when using a variable on the right side, the quotes must be included

in
the variable's value or you can concatenate them on as follows:

wholeRange.End(xlToRight).Name = "" & rngName(intI) & ""

--
Jay


"Carol G" wrote:

I'm sorry I don't even know what the current region is yet.
I don't think this will work because I also don't know what the address

of
the cell is (only that it is to the right of my last cell. I just

thought
I'd go to the last column used, populate the one to the right and then
assign a name to that column using a string array that holds the 5

names,
loop through and do the same thing for 4 more columns after that.
The problem is that I don't know the excel object very well so I don't

know
how to write out the left hand side of the assignment statement.
Hopefully I'm making more sense.
Thanks for your help Jay
Here's my code so far.
Carol


Sub SortByPriceDifference()
Dim wholeRange As Range
Dim MyWorksheet As Worksheet
Dim rw As Range
Dim Difference As Integer

'Set MyWorksheet = Worksheets("LouieData").Activate
Set wholeRange = ActiveSheet.UsedRange
Dim intI As Integer
Dim arrI(5) As Integer

For Each rw In wholeRange.Rows
Difference = rw.Columns("H") - rw.Columns("G")
Select Case Difference
Case Is < -15000 'More Than -15,000
arrI(0) = arrI(0) + 1

Case -15000 To -10000 'Between 10,000 and 15,000 Below
arrI(1) = arrI(1) + 1

Case -9999 To -5000 'Between 5,000 and 10,000 Below
arrI(2) = arrI(2) + 1

Case -4999 To 0 'Between 0 and 5000 Below
arrI(3) = arrI(3) + 1

Case Else 'Sold OverPrice
arrI(4) = arrI(4) + 1

End Select
Next
For intI = 0 To 4
wholeRange.End(xlToRight).Next = arrI(intI)
???? here is where I want to assign the name looping through an array of

5
names.


Next

End Sub
"Jay" wrote in message
...
Hi Carol -

You might be able to name your columnar range AFTER you populate it

by:

Range("C10").CurrentRegion.Name = "CarolsRangeName"
(where "C10" is a cell inside your populated range.)

I'm not getting the exact picture of what you want to do. If the

above
suggestion doesn't do what you want it to do, please reply with a bit

more
detail.
--
Jay


"Carol G" wrote:

I am populating these cells with data but I don't know how to Name

the
columns that the new data is in.
Thanks for any help. I am brand new at excel.
CArol


For intI = 0 To 4
wholeRange.End(xlToRight).Next = arrI(intI)
???? = Name(intI).Value
Next