Avatar billede Ingolf Juniormester
28. maj 2020 - 17:56 Der er 3 kommentarer og
2 løsninger

Makro i Excel diagram

Er det muligt at oprette en makro i et diagram, der har til opgave at ændre minimums værdien for den lodrette akseindstilling.

Jeg har brug for skiftevis at kunne indsætte/udskifte minimumsværdierne til nedenstående værdier:
60
70
80
90
100
Dette for at undgå, at diagrammet automatisk viser fra 0 (nul) og opefter når der indtastes værdier, og man ikke har sat et minimumsværdi.

Håber der vil være en løsning på det.
Avatar billede jens48 Ekspert
29. maj 2020 - 10:51 #1
Er det noget i denne stil du er ude efter? Hver gang makroen aktiveres skifter min. værdien.

Sub Macro1()
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.Axes(xlValue).Select
    If ActiveChart.Axes(xlValue).MinimumScale = 50 Then
    ActiveChart.Axes(xlValue).MinimumScale = 60
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 60 Then
    ActiveChart.Axes(xlValue).MinimumScale = 70
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 70 Then
    ActiveChart.Axes(xlValue).MinimumScale = 80
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 80 Then
    ActiveChart.Axes(xlValue).MinimumScale = 90
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 90 Then
    ActiveChart.Axes(xlValue).MinimumScale = 100
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 100 Then
    ActiveChart.Axes(xlValue).MinimumScale = 50
  End If
  End If
  End If
  End If
  End If
  End If
  Application.CommandBars("Format Object").Visible = False
  Range("A1").Select
 
End Sub
Avatar billede jens48 Ekspert
29. maj 2020 - 10:55 #2
Hvis du retter 4. linje til

  If ActiveChart.Axes(xlValue).MinimumScale <= 50 Then

.så starter de også ok, selv om minimumsværdien er 0
Avatar billede Ingolf Juniormester
29. maj 2020 - 12:20 #3
Hej Jens48

Hvis jeg kan få din løsning til at fungere vil det være rigtig fint. Jeg havde selv tænkt på at koble en Makro til en Knap for hver værdi.
Jeg kan se nu, at jeg skulle have vendt talrækken om, med det største tal først.
Jeg ser på det.
Avatar billede Ingolf Juniormester
29. maj 2020 - 15:48 #4
Hej Jens48

Jeg har nu fået det til at fungere. Jeg har vendt talrækken om. Starter fra 100 og går trinvis 5 ned til 55. Jeg har koblet en knap til Makroen.
Dog kan jeg ikke få det til at fungere, hvis jeg tilføjer følgende linier fra dit forslag:

Application.CommandBars("Format Object").Visible = False
Range("A1").Select

Hvad betydning har de 2 linier? Sker der noget ved at undlade dem?

Koden ser herefter sådan ud nu:
Sub Makro100()
'
' Makro100 Makro
'
' Ændrer lodret akse trinvis med 5 fra 100 til 55

    ActiveSheet.ChartObjects("Diagram 1").Activate
    ActiveChart.Axes(xlValue).Select
       
   
    If ActiveChart.Axes(xlValue).MinimumScale > 100 Then
    ActiveChart.Axes(xlValue).MinimumScale = 100
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 100 Then
    ActiveChart.Axes(xlValue).MinimumScale = 95
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 95 Then
    ActiveChart.Axes(xlValue).MinimumScale = 90
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 90 Then
    ActiveChart.Axes(xlValue).MinimumScale = 85
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 85 Then
    ActiveChart.Axes(xlValue).MinimumScale = 80
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 80 Then
    ActiveChart.Axes(xlValue).MinimumScale = 75
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 75 Then
    ActiveChart.Axes(xlValue).MinimumScale = 70
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 70 Then
    ActiveChart.Axes(xlValue).MinimumScale = 65
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 65 Then
    ActiveChart.Axes(xlValue).MinimumScale = 60
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 60 Then
    ActiveChart.Axes(xlValue).MinimumScale = 55
    Else
    If ActiveChart.Axes(xlValue).MinimumScale = 55 Then
    ActiveChart.Axes(xlValue).MinimumScale = 100

End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If


End Sub
Avatar billede jens48 Ekspert
29. maj 2020 - 15:56 #5
Det var vist et par koder der kom ind ved en fejl. De skal blot udelades
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester



IT-JOB