Charts in vba excel

KP007

New Member
Joined
Nov 17, 2021
Messages
6
Office Version
  1. 365
Platform
  1. Windows
I am currently designing a user form for employee information. I need to generate a line chart of any employee using their employee id as a reference to make a line graph of their daily temperature over a period of time.

I have created the user form already and have the line chart in excel already, however, I want the chart generated via a search button and user form and image.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
KP007 and Welcome to the Board! In it's simplest form, U add an image control to the userform and run the following code. Adjust the userform name and image control name as necessary. HTH. Dave
Code:
Dim Fname As String
Fname = ThisWorkbook.Path & "\" & "Filename.gif"
ActiveChart.Export Filename:=Fname, FilterName:="GIF"
Userform1.Image1.Picture = LoadPicture(Fname)
Kill Fname
 
Upvote 0
screenshot1.png

I know very little in vba. I have been using youtube to help me with all my coding.

This is a screenshot of the table, I am using the search button to call an employee with temperatures and the line chart should generate in the image.

I would appreciate any additional help.

I have tired the above mentioned code and I am getting an error run-time 91
 
Upvote 0
Where is the chart... sheet1? What is the name of the chart... chart1? What is the name of the userform... userform1? Do you have an image control... image1? On what line is the error occurring? Dave
 
Upvote 0
Where is the chart... sheet1? What is the name of the chart... chart1? What is the name of the userform... userform1? Do you have an image control... image1? On what line is the error occurring? Dave
The chart is on a sheet called chats. The chat has the default name as chart1. The user form that I need the chart on is called chart. I do have an image control as image1. I am sure I am using the code incorrectly. The error is no longer showing, for some reason.

So I need all the values in the text boxes with the dates to make the chart.

That information has inputted by a user controller and saved on the main data sheet called "data", from data it is then transferred to a sheet called "charts" where the chart is already working. I just need it to come up, on the user form when I search for an employee via their "barcode" number. That is where I am stuck and would really appreciate the help.
 
Upvote 0
Hi KP007. Using "Chart" as the name of the userfom won't work. "Chart" is an XL term that should not be used for any other reason than to refer to a chart. Anyways, if you have an embedded chart on a sheet named "charts", with a name "Chart 1" and you have an image control named "image1" on a re-named userform "Userform1" then this code will work. It sizes your chart but may need some further aspect ratio code. Give it a trial. Dave
Code:
Sub testchart()
Dim Fname As String, CurrentChart As Chart
Fname = ThisWorkbook.Path & "\" & "Filename.gif"
Set CurrentChart = Sheets("Charts").ChartObjects("Chart 1").Chart
'size chart to fit image control
With CurrentChart
.Parent.Width = Userform1.Image1.Width
.Parent.Height = Userform1.Image1.Height
.Export Filename:=Fname, FilterName:="GIF"
End With
Userform1.Image1.Picture = LoadPicture(Fname)
'remove temp file
Kill Fname
End Sub
 
Upvote 0
Solution
Thank you so much for the help. Once I changed the chart name everything came. I was also able to get the different chats to come up as I called each employee.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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