Move Chart Data Labels with arrow keys

JeffFinnan

New Member
Joined
Aug 12, 2020
Messages
47
Office Version
  1. 2019
Platform
  1. Windows
Is there a way to move labels in a chart, more specially data labels, with arrow keys? I would like to move some labels either straight up or down. By the way these labels are generated from a third columns.

Thanks,
Jeff
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I think you will need vba for this.

Assuming your chart name is Chart 1 and it is located in Sheet1

Place this code in the ThisWorkbook Module:
VBA Code:
Option Explicit

Private Const TARGET_SHEET = "Sheet1"   '<< change sheet name as required.
Private Const TARGET_CHART = "Chart 1"  '<< change chart name as required.

Private WithEvents chrt As Chart

Private Sub Workbook_Activate()
    HookChart Sheets(TARGET_SHEET).ChartObjects(TARGET_CHART).Chart
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    HookChart Sheets(TARGET_SHEET).ChartObjects(TARGET_CHART).Chart
End Sub

Private Sub HookChart(ByVal oChart As Chart)
    Set chrt = oChart
End Sub

Private Sub chrt_Activate()
    Application.OnKey "{UP}", "'" & Me.CodeName & ".KeyStroke " & True & "'"
    Application.OnKey "{DOWN}", "'" & Me.CodeName & ".KeyStroke " & False & "'"
End Sub

Private Sub chrt_Deactivate()
    Application.OnKey "{UP}"
    Application.OnKey "{DOWN}"
End Sub

Private Sub KeyStroke(bUpArrowKey As Boolean)

    Const JUMP = 20 '<< change as required.

    If TypeName(Selection) = "DataLabel" Then
        If bUpArrowKey Then
            Selection.Top = Selection.Top - JUMP
        Else
            Selection.Top = Selection.Top + JUMP
        End If
    End If

End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,945
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top