Thread: select next
View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Tom Ogilvy Tom Ogilvy is offline
external usenet poster
 
Posts: 6,953
Default select next

If you look at your code at the end, the selection is not a chartobject. I
gave you code to handle this in a previous thread.

here is a simpler version of that code:

Sub AA_SelectNext()
Dim obj As Object
If Not ActiveChart Is Nothing Then
Set obj = ActiveChart.Parent
i = obj.Index
obj.TopLeftCell.Select
If i < ActiveSheet.ChartObjects.Count Then
ActiveSheet.ChartObjects(i + 1).Select
Else
ActiveSheet.ChartObjects(1).Select
End If
Else
MsgBox "chartObject is not selected"
End If

End Sub

Unfortunately, there is not one line of code that will do this that I am
aware of.
ActiveChart.Next does not work for what you want.

--
regards,
Tom Ogilvy


"BorisS" wrote:

so here is what I have (graphs), and it is not working:

Dim cobj As ChartObject

For Each cobj In ActiveSheet.ChartObjects

ActiveChart.Axes(xlValue, xlPrimary).Select
Selection.TickLabels.NumberFormat = "#,##0.0_);[Red](#,##0.0)"
Selection.TickLabels.AutoScaleFont = True
With Selection.TickLabels.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With
ActiveChart.Axes(xlValue, xlSecondary).Select
Selection.TickLabels.NumberFormat = "#,##0_);[Red](#,##0)"
Selection.TickLabels.AutoScaleFont = True
With Selection.TickLabels.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
.Background = xlAutomatic
End With

Next cobj

End Sub


again, however, my ideal scenario is not to have the macro go automatically
through each chart. Rather, I have some sheets where I need it just to go
through all, make changes I indicate, and then be done with the sheet.

but other sheets, I actually would prefer to go one by one, however not
having to hold the mouse and click on each successive graph. I want to
assign a shortcut key to run (I'll select the first graph), and end with a
line that basically does the same as simply clicking on the next graph (but
not running the macro over (which I understand for-each will force it to do).
Then once it's selected the next graph, I'll again hit the shortcut if I'm
sure I want to run it on that graph.

Thx for any further help.
--
Boris


"xlbo" wrote:

The exact syntax will depend on the objects you are trying to llop through
but essentially you need a For Each..Next loop through the object collection
so

For each objectVariable in SheetRef.objectCollection
Process objectVariable
Next

so to iterate through the textboxes on a sheet, you would reference the
SHAPES collection:

For Each shp In ActiveSheet.Shapes
MsgBox shp.Name
Next
--
Rgds, Geoff




"BorisS" wrote:

I need for a macro to run and then have the next object selected. What is
the one line that will get me that "select next object in the sheet" code? I
don't want it to go through all of them, just to do the equivalent of
clicking on the next graph I have in number order.

Thx.
--
Boris