• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 641
  • Last Modified:

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

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
Kelvin4
Asked:
Kelvin4
  • 2
  • 2
1 Solution
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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
 
Kelvin4Author Commented:
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
 
Scott HelmersVisio Consultant, Trainer, Author, and DeveloperCommented:
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
 
Kelvin4Author Commented:
Many thanks
Kelvin
0

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now