Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Programming a NAME
I need to place several "blocks", each block consisting of several cells with
values and references to other values (in other blocks). The number of these blocks of cells is not fixed - it will change at run time based on user input. So for each block, I need to be able to refer to the values elsewhere on the sheet. I am using a Type called "converter", which has several members, those being the cell location where the block is placed (the block contains 9 cells, the reference location is one of these cells, and the other values are placed relative to that cell). My Type definition looks like this (this is truncated); Public Type Converter_Type Efficiency(50) As Double Pdiss(50) As Double Vin(50) As Double Col(50) As Integer 'the reference column number Row(50) As Integer 'the reference row number End Type Public Converter = Converter_Type So then, as the user adds one of these blocks, 9 cells are filled. Some are text, most are values. Some of these are used by other blocks used elsewhere. So I need to refer to each cell by name, so that I can build meaningful expressions for the other calculations. This is where I am stumped. The excel equivalent of what I want to do is to define a Name for each cell's contents. Here is what I have now (one of the many versions that I have tried): ActiveWorkbook.Names.Add name:="ConvVout" & LTrim(Str(n)), _ RefersToR1C1:="Sheet1!" & (convert_asc(Converter.Col(n) + 1)) _ & LTrim(Str(Converter.Row(n))) What I am trying to do in this statement is assign the name ConvVout1 to the value in the cell just to the right of the "reference cell". The reference cell is located at the row and column saved with the Type variable in the Row and Col elements. That is, the reference cell is at Converter.Row(n) and Converter.Col(n). Executing this code results in a name definition that reads correctly in the worksheet (reading it at the Edit/Define page). That is, it says that cell G15 has the name =ConvVout1 for example. But if I edit a cell (manually) and place "=ConvVout1", what I get in that cell is the name of the cell where the value of ConvVout1 exists. So for example, I get Sheet1!G15 in that cell. Not the number that's in G15, which is what I want. I hope all that makes sense. If you have made it this far, thanks. I have been working on this for hours and can't make it work right. I have been trying to figure out the difference between the various versions of "refersto". Documentation is very unclear. Thanks in advance! dan |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
programming help | Excel Discussion (Misc queries) | |||
programming | Excel Programming | |||
programming VBA | Excel Programming | |||
Programming in VB | Excel Programming | |||
vba programming | Excel Programming |