Visio shapesheet get Layer index from name - layer

I have some defined shapes in a Visio 2010 stencil, and would like to set the layer depending on the value of a particular shape data field. I would like to do this within the shapesheet if at all possible, since my workplace is very limiting concerning the use of VisualBasic.
I can do the necessary look up to find a particular value, but need to translate this to the correct index in the page layers list.
Basically, I need to get the current index of a particular layer. For example, I know the name of the layer is "Remove" and need the index in ThePage!Layers so that I can set LayerMember accordingly. The index changes from page to page, so I need do this lookup in the context of the page after the shape has been dropped on the page.
How can I look up the index of an entry in ThePage!Layers, using the name of the layer as lookup index. A syntax like ThePage!Layers.Index["Remove"] doesn't work and I couldn't find any other information in the Microsoft documentation.

It is possible! My method
i add to my shape 3 sections: User-definded cells, Shape Data, Layer Membership.
In Shape Data section i create one row, which contain Layer Name selector
User-definded cells section contain two rows:
1. User.L_List store list of all layers on page. I prepare this list use MS Excel
In column A i fill row numbers, like as at this picture
In cell B1 i place formula - Concatenate("ThePage!Layers.Name";A1)
In cell B2 i place formula - Concatenate(B1;"&Listsep()&ThePage!Layers.Name[";A2;"]")
And pull down some rows as i need.
Select bottom cell in column B and copy that value
Paste this value in MS Visio's cell User.L_List
2. Next cell contain formula SETF(GetRef(LayerMember),LOOKUP(Prop.LayerName,User.L_List)),
which assign shape to layer according value in Prop.LayerName cell

Related

VLookup table array from another sheet

Ive a sheet in which a cell value to be dynamically changed based on the cell value in the same row. So we have to pick that cell value first and then use that value to search in another sheet. Here is the code I have got. The sheet I have to search is Mapper
ActiveSheet.Range("P2").Select
formularwcount = ActiveSheet.UsedRange.Rows.Count
ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-11], Mapper!C[-13]:C[2],3,FALSE)"
In this code they are using R1C1 convention which I didnt understand what they mean by putting Mapper!C[-13]:C[2] there as the table array. Im only a 10 days old developer with VBA. Anyone please tell what does that mean.
I found this information by Googling "R1C1":
Cell References
In place of a named cell, an alternative approach is to use a cell (or grid) reference. Most cell references indicate another cell in the same spreadsheet, but a cell reference can also refer to a cell in a different sheet within the same spreadsheet, or (depending on the implementation) to a cell in another spreadsheet entirely, or to a value from a remote application.
A typical cell reference in "A1" style consists of one or two case-insensitive letters to identify the column (if there are up to 256 columns: A–Z and AA–IV) followed by a row number (e.g., in the range 1–65536). Either part can be relative (it changes when the formula it is in is moved or copied), or absolute (indicated with $ in front of the part concerned of the cell reference).
The alternative "R1C1" reference style consists of the letter R, the row number, the letter C, and the column number; relative row or column numbers are indicated by enclosing the number in square brackets. Most current spreadsheets use the A1 style, some providing the R1C1 style as a compatibility option.
Source: Wikipedia: Spreadsheets

Excel VBA Changing text inside shapes based off a range of cells

I have made a large diagram of made by shapes with numbers stored inside as text and need to change the "old" numbers to a "new" range of numbers. On each of the 20 sheets there are circles, Rectangles, Left Arrows and Right Arrows. The old range of numbers are stored on a separate spreadsheet in the Column "A" and need to be changed to the numbers listed in Column "B" (as in A1 to B1).
What would a VBA method to change the old text inside the Shapes to the new correct text based off of a new range of numbers? Is it possible to write a script that changes the values in the entire WorkBook?
My incorrect way of thinking is to:
1. Search inside the diagram to find the various shapes.
2. Get the text inside each shape.
3. Compare the text with the spreadsheet with the old numbers.
4. Insert the new number.
5. Move onto the next shape.
Put a value in A1 and say we already have a Shape:
Running this:
Sub LinkCellToShape()
Dim sh As Shape
Set sh = ActiveSheet.Shapes(1)
sh.DrawingObject.Formula = "=A1"
End Sub
will link the text in the shape to the value in the cell. You could also use:
sh.OLEFormat.Object.formula = "=A1"

Excel Cell reference that will go to the left

I am using an excel spreadsheet formula to add two cells together and I want to have it reference one row from left to right like it normally does, but I need it to reference the same row in another page in reverse, and then be able to drag the formula through the entire worksheet. I cannot seem to find anything like this when I look online. TLDR I need to know how to tell excel reference the cell to the left if I drag it to the right.
so I need to add A0 in page one and A9 in page two then when I copy the formula to the left I need it to grab A1 and A8, is there a way to get this?
Your question is not very clear; for example, you talk about a formula but have an Excel-VBA tag. However, I think I understand the effect you seek.
I have filled A1:I1 of the current sheet and A1:I1 of worksheet “Sheet3” with numbers.
I have typed the following formula into another cell within the current worksheet:
=A1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(A1))
The target area for the INDEX function is Sheet3!$A$1:$I$1. This is a one row range so I do not need a row number. The column number is 10-COLUMN(A1) which is 9 so this formula is equivalent to:
=A1+Sheet3!I9
If I copy the formula one cell to the right I get:
=B1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(B1))
This is the equivalent of:
=B1+Sheet3!H9
You can continue copying the formula to the right until you get:
=I1+INDEX(Sheet3!$A$1:$I$1,,10-COLUMN(I1))
Attempting to copy further gives an error because 10-COLUMN(J1) is zero and there is no column 0.
There are other methods of achieving this effect. The key feature of any such method is the expression N-X where N is a constant and X gets bigger as the formula is copied further to the right.

Number to be copied from cell with the same number format and show it as a label for a shape without any change in the number format

I have a cell in excel which contains a value, lets say 100000.
Now i want this value to have commas in between them to represent the thousands and millions i.e. 100,000. I can do this by changing the number format in the home menu.
Now i want this value to be copied from that cell and paste it as a label for a shape. When i am doing this the commas go away showing me just the numbers.
I want it to happen through VBA but this is not happening in excel itself.
Does anyone have a plausible solution for this?
In range object use Text property, like this:
Sheet1.Shapes(1).TextFrame.Characters.Text = Range("A1").Text

Excel Macro - Search Range of Cell for 0, then return "empty" cell

This is my first time using this forum, and my VBA skill is not very well developed. I hope someone can help.
I have two columns of data, Column A and Column B.
Column A - Returns a sequential "month-year" or 0. If spreadsheet current date (=now()) is less than say Feb, then the cell for February returns 0.
Column B - I want this column to check each cell in Column A. If Column A cell has a date identifier, I want this to be placed in Column B. If Column A has a 0 identifier, I want Column B to return an "empty" cell.
Reason why I am doing this is I am graphing a bar chart. When I trick the program into making an empty cell (x-axis) the graph does not show any data for that month (which is what I want). Trying to make a dynamic graph, but I have no experience in VBA (only C programming =/).
You don't need VBA (or even formulas) to do this.
Highlight Column A (the entire column), copy it.
Highlight Column B (the entire column, right click, Paste Special, select values and number formats, okay.
Highlight Column B again. Press Ctrl+H, Type 0 (or failing that it might be 00/01/1900) in the 'find what', leave the 'replace with' one blank. Tick Match entire cell contents. Click replace all.
Done.
Instead of trying for an empty space (which would be impossible, as there's a formula in that cell), use an error condition.
Use this formula, and copy down:
=IF(A1=0,NA(),A1)
This will return the error condition #NA! and Excel will leave the column blank
The other way would be to have a dynamic range for the chart data - I have a chart that will adjust to 5,6 or 7 days, depending on the data returned for the week. The Horizontal (Category) Axis Labels is set to a named range (='Sample.xlsx'!LastWeekRange) and the range checks the data, and returns the appropriate number of cells.
LastWeekRange is defined in Name Manager as =OFFSET(Data!$A$3,0,0,IF(Data!$F$9>0,7,IF(Data!$F$8>0,6,5))), which returns A3:A7 if there's nothing in F8, A3:A8 if there is something in F8 but not in F9, and A3:A9 if there is something in F9.