[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

writing to a shapesheet section via CellsSRC - but from the bottom row upwards!

Posted on 2011-09-27
4
Medium Priority
?
625 Views
Last Modified: 2012-05-12
I hope I'll kick myself:
This code loads "test_1" through to "test_10" into Scratch column A.
Whilst debug.print shows a progression of values through a For loop from "test_1" to "test_10", the values appear in the scratch section with  "test_10" on the first scratch row, and  "test_1" on the last (bottom) row. Why? and How do I invert the order in the scratch rows?
--------
Sub Scratch()
Dim pag As Visio.Page
Dim shps As Visio.Shapes
Dim cel As Visio.Cell
Dim i As Integer
Dim str As String
Dim rowCount As Integer
Set pag = ActivePage
Set shps = pag.Shapes
str = "test_"
For i = 1 To 10
    shps.ItemFromID(1).AddRow visSectionScratch, visRowScratch, 0
    rowCount = shps.ItemFromID(1).rowCount(visSectionScratch)
    Set cel = shps.ItemFromID(1).CellsSRC(visSectionScratch, visRowScratch, visScratchA)
     cel.Formula = Chr(34) & str & i & Chr(34)
    Debug.Print "shp.rowCount(visSectionScratch) = "; rowCount
    Debug.Print "str & i = "; str & i
Next i
End Sub

--------
Kelvin4

0
Comment
Question by:Kelvin4
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 31

Expert Comment

by:Scott Helmers
ID: 36720525
Kelvin: I'm in an airport without time to respond today... but I'll get back to this in the next day or so.

In the meantime, if anyone else gets to this first, that's fine with me.

Scott
0
 

Author Comment

by:Kelvin4
ID: 36899949
Scott: Thanks for the quick note above,
The question is not a show-stopper, but seeks to improve my basic understanding.
I can wait til you are free
Best,
Kelvin,
0
 
LVL 31

Accepted Solution

by:
Scott Helmers earned 2000 total points
ID: 36901201
Kelvin,

The culprit is using visRowScratch when you add each row to the Scratch section. If you look in the help text, that value is the "Index of the first row in visSectionScratch". In the code below I've used visRowLast instead.

BTW, I also streamlined the code by setting rowCount as part of the AddRows method. This eliminates the need for the separate rowCount assignment statement that I've commented out.

Final comment: note that the first row is row zero.

Scott
Sub ScratchLast()
Dim pag As Visio.Page
Dim shps As Visio.Shapes
Dim cel As Visio.Cell
Dim i As Integer
Dim str As String
Dim rowCount As Integer
Set pag = ActivePage
Set shps = pag.Shapes
str = "test_"
For i = 1 To 10
    ' CHANGE MADE HERE                                      vvvvvvvvvv
    rowCount = shps.ItemFromID(1).AddRow(visSectionScratch, visRowLast, 0)
    ' STATEMENT BELOW NO LONGER REQUIRED
    'rowCount = shps.ItemFromID(1).rowCount(visSectionScratch)
    ' CHANGE MADE HERE                                       vvvvvvvv
    Set cel = shps.ItemFromID(1).CellsSRC(visSectionScratch, rowCount, visScratchA)
     cel.Formula = Chr(34) & str & i & Chr(34)
    Debug.Print "shp.rowCount(visSectionScratch) = "; rowCount
    Debug.Print "str & i = "; str & i
Next i
End Sub

Open in new window

0
 

Author Closing Comment

by:Kelvin4
ID: 36902640
Many thanks
Kelvin
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever created a custom Visio stencil – a collection of your own unique master shapes – and then created a drawing by dragging masters onto the drawing page? Have you then made changes to the stencil master and wondered why the shapes on the …
The ability to add structure to Visio diagrams using containers, lists and callouts is one of my favorite features in Visio 2010. In this article I’ll describe a mashup of containers and lists that meet a real-world need. Prior to reading this ar…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question