View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
external usenet poster
 
Posts: 536
Default Naming non-contigent cells with vba

This code from help works fine to name cells B1 to B5 with the text in A1 to A5.
How do I modify it to name cells B1, F1 and K1 with the text in A1 and to name cells B2, F2 and K2 with the text in A2 and so on?

So with text in A1 = Data1 then cells B1,F1 and K1 are named Data1,
the text in A2 = Data2 then cells B2, F2 and K2 are named Data2.

This is for a possible solution to a poster who wants
to produce the sum of three non contingent cells from one sheet to another sheet. I suggested naming the range Data and on the other sheet =SUM(Data).
I then learn he has 200+ rows. Presents a tedious problem in naming.

Code to sum the non-contigent cell on sheet1 and zip the totals over to sheet2 is certanily a possibility. However, the poster did not know how to name a range so I am assuming a very new user who would be more comfortable with some simpler formulas once all the naming gets done.

Option Explicit

Sub NameIt()
Dim rangeToName As Range
Set rangeToName = Worksheets("Sheet1").Range("A1:B5")
rangeToName.CreateNames Left:=True
End Sub

'This example creates names for cells B1:B3 based on the text in cells A1:A3.
'Note that you must include the cells that contain the names in the range,
'even though the names are created only for cells B1:B3.

Thanks,
Regards,
Howard