Archive for Charting

Archives

  1. ActiveX Programming
  2. Add an Image to Cell Comments
  3. Add Sheet Navigation CommandBar to an Excel file or Application
  4. Auto-Generate a File Name
  5. Automate File Download from Internet
  6. Automate WebLogin…
  7. Convert Decimal to RGB Color Value
  8. Copy Ranges from Different Sheets into one Sheet
  9. Create HyperlinkObject on Sheet
  10. Create LogFile for Workbook Open
  11. Create Sheet “Table of Contents”
  12. Create ShortCut Link at the desired location
  13. Create UserForm at Runtime using Code
  14. Display Userform with no Title Bar (Splash Screen)
  15. Downloads
  16. Downloads from www.jkp-ads.com
  17. Export a Text File with Comma and Quote Delimiters
  18. Get elements from HTML form
  19. Get FileName with Path from User
  20. Get FileNames with Path from User
  21. Hyperlink Elements in HTML
  22. Ken’s Knowledge Base submissions
  23. Login to Rediffmail
  24. Move a File
  25. Multiple Cell Concatenation
  26. Other Site Links
  27. Read CSV Using VBA techniques
  28. Remove Unprintable Character & Spaces from cells
  29. Rename a File
  30. Rename Files using Codes (VBA)
  31. Resources
  32. Resources
  33. Search Folders and Subfolders for files
  34. Show Status on Userform While executing Code
  35. Site Contents
  36. socko.wordpress.com — Technorati Search
  37. Sort WorkSheets by Name
  38. Sorting Text with Worksheet Formula
  39. test
  40. Use of vbScript in Database Applications
  41. Userform Resizer – VBA
  42. Userforms
  43. VBA Code Library
  44. vbaX KB Links
  45. Verify that a File Exists
  46. Web Forms manipulated by Visual Basic
  47. Write to & Read from Sequential Text Files
Advertisements

Leave a Comment

Displaying A Chart In A Userform

– Selva V Pasupathy, HSBC Global Resourcing

Original Source: John Walkenbach

I was pretty impressed when I came across a page where John has mentioned how you can use userform to show all the chrts in a spreadsheet on a userform and you can move betwee different charts with the help of a commandbutton.

Image showing how your userform with chart will look like

HOW SHOULD I USE THE FOLLOWING CODE

Copy the code below and paste in code section of a userform

Dim ChartNum As Integer

Private Sub UserForm_Initialize()
    ChartNum = 1
    UpdateChart
End Sub

Private Sub PreviousButton_Click()
    If ChartNum = 1 Then ChartNum = 3 Else ChartNum = ChartNum - 1
    UpdateChart
End Sub

Private Sub NextButton_Click()
    If ChartNum = 3 Then ChartNum = 1 Else ChartNum = ChartNum + 1
    UpdateChart
End Sub

Private Sub CloseButton_Click()
    Unload Me
End Sub

Private Sub UpdateChart()
    Set CurrentChart = Sheets("Charts").ChartObjects(ChartNum).Chart
    CurrentChart.Parent.Width = 300
    CurrentChart.Parent.Height = 150

'   Save chart as GIF
    Fname = ThisWorkbook.Path & Application.PathSeparator & "temp.gif"
    CurrentChart.Export FileName:=Fname, FilterName:="GIF"

'   Show the chart
    Image1.Picture = LoadPicture(Fname)
End Sub

Copy the code below and paste in a code module.

Sub ShowChart()
    UserForm1.Show
End Sub

Download the example file from here CLICK HERE

Leave a Comment