Help adding input box to macro

ttbuson

Board Regular
Joined
Nov 18, 2011
Messages
80
Hi All,

I'd like to add a message box to the following macro.

Code:
Sub FormatDataPoints()
 
Dim i As Long

    With ActiveSheet.ChartObjects("Chart 1").Chart
        For i = 1 To 10
            With .SeriesCollection(i)
                .MarkerStyle = 2
                .MarkerSize = 7
                .Format.Fill.ForeColor.RGB = RGB(0, 128, 0)
                .Format.Line.Visible = msoFalse
                .ApplyDataLabels
                    With .DataLabels
                        .ShowSeriesName = True
                        .ShowValue = False
                        .Position = Above
                        .Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 128, 0)
                    End With
            End With
        Next i
    End With
 
End Sub

Basically, I'd like to have a message box come up that asks the user to define which series the formatting should be applied to. So, the line in the macro where it says For i = x to y would be defined by the message box.

I'd also like to have a message box that would allow a user to select what color they wanted to use for the formatting, with the names matched to a list of RGB values. The part in the macro where it lists the RGB value to use would come from that input.

Any help would be appreciated, I've never used a message box or input box before. Thank you!
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi All,

I'd like to add a message box to the following macro.

Code:
Sub FormatDataPoints()
 
Dim i As Long

    With ActiveSheet.ChartObjects("Chart 1").Chart
        For i = 1 To 10
            With .SeriesCollection(i)
                .MarkerStyle = 2
                .MarkerSize = 7
                .Format.Fill.ForeColor.RGB = RGB(0, 128, 0)
                .Format.Line.Visible = msoFalse
                .ApplyDataLabels
                    With .DataLabels
                        .ShowSeriesName = True
                        .ShowValue = False
                        .Position = Above
                        .Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 128, 0)
                    End With
            End With
        Next i
    End With
 
End Sub

Basically, I'd like to have a message box come up that asks the user to define which series the formatting should be applied to. So, the line in the macro where it says For i = x to y would be defined by the message box.

I'd also like to have a message box that would allow a user to select what color they wanted to use for the formatting, with the names matched to a list of RGB values. The part in the macro where it lists the RGB value to use would come from that input.

Any help would be appreciated, I've never used a message box or input box before. Thank you!


For the first part of your question, would something like this be what you want?

Code:
Sub FormatDataPoints()
 
Dim i As Long
Dim x As Integer
Dim y As Integer

x = InputBox("Please Enter the Starting Number")

y = InputBox("Please Enter the Ending Number")

    With ActiveSheet.ChartObjects("Chart 1").Chart
    
        For i = x To y
        
            With .SeriesCollection(i)
                .MarkerStyle = 2
                .MarkerSize = 7
                .Format.Fill.ForeColor.RGB = RGB(0, 128, 0)
                .Format.Line.Visible = msoFalse
                .ApplyDataLabels
                    With .DataLabels
                        .ShowSeriesName = True
                        .ShowValue = False
                        .Position = Above
                        .Format.TextFrame2.TextRange.Font.Fill.ForeColor.RGB = RGB(0, 128, 0)
                    End With
            End With
        Next i
    End With
 
End Sub
 
Upvote 0
Yes! That is exactly what I was looking for. Thank you so much for this; you are awesome. Any advice for the second part?
 
Upvote 0
Yes! That is exactly what I was looking for. Thank you so much for this; you are awesome. Any advice for the second part?


You're welcome. Glad too help out, and thanks for the feedback. I'll be off the board until tomorrow, and if no one else helps you with part two by then, I'll see what I can do.
 
Upvote 0

Forum statistics

Threads
1,215,326
Messages
6,124,268
Members
449,149
Latest member
mwdbActuary

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