Determine range for chart data using userform input - VBA

dlee83

New Member
Joined
Mar 11, 2022
Messages
20
Office Version
  1. 365
Platform
  1. Windows
Good Evening,

Any help appreciated in advance.

I'm looking to generate simple charts using data decided by the user inputting chosen dates from a userfrom.
The dates are along e2:av2 so the user can select from that array (they will decide on charttype and dataset, but I'll come to that when I can do this)

I need the chart to then use the selected dates range of data. How do I determine the range so that the chart can use those cells??

Private Sub CommandButton2_Click()

'Dim charttype As String
'Dim dataset As String

Dim dat1 As String
Dim dat2 As String

Dim r As Range
Dim cec1 As Range
Dim cec2 As Range

'charttype = ComboBox1.Value
'dataset = ComboBox2.Value

dat1 = ComboBox3.Value
dat2 = ComboBox4.Value

Set r = Range("e2:av2")

For Each cell In r
If cell.Value = dat1 Then
cell.Activate
Set cec1 = ActiveCell
End If
Next

For Each cell In r
If cell.Value = dat2 Then
cell.Offset(1, 0).Activate
Set cec2 = ActiveCell
End If
Next


ActiveSheet.Shapes.AddChart2(201, xlColumnClustered).Select
ActiveChart.SetSourceData Source:=Range("Budget!???:???")


End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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