{"id":4682,"date":"2016-10-07T18:40:24","date_gmt":"2016-10-07T18:40:24","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/wp\/?p=4682"},"modified":"2017-11-22T16:38:19","modified_gmt":"2017-11-22T16:38:19","slug":"button-to-zoom-in-a-graph-in-excel-method-2","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/","title":{"rendered":"Button to Zoom in a Graph in Excel – [Method 2]"},"content":{"rendered":"

Hello Friends,<\/p>\n

How are you doing? I am back with my next article about “how to make a button to zoom-in and zoom-out a graph in Excel VBA”. this is the second method I am going to explain you. In my previous article, I had explained about the very basic method.<\/a><\/p>\n

There were 4 limitations in the previous method which I explained it. In this article I am going to address all the limitations mentioned in the previous method.<\/p>\n

This method is going to be an illusion created for zoom-in and zoom-out \ud83d\ude09<\/p>\n

Steps to create Zoom-in Zoom-out button for Graph<\/h1>\n

1. Taken input from the user about the width or Height
\n2. Resize the graph with that size (DO NOT SHOW THIS TO USER HAPPENING… by using below VBA statement<\/em>) <\/p>\n

\r\nApplication.ScreenUpdate = False\r\n<\/code><\/pre>\n

3. Now save this large graph as an image in the temp folder.
\n4. Create a UserForm and add a placeholder for an image
\n5. Make the UserForm hegiht and width as “auto” – So that form size get adjusted according to the size of the image
\n6. While loading or showing the UserForm, embed the image which you have saved it in the temp folder.
\n7. Now on closing the userform having graph image, delete the image which you saved it in the temp folder and release the memory.<\/p>\n

Important<\/h1>\n

In the above steps, the sequence of step 2 and 3 is very important<\/strong>. If you are resizing the image after saving it, then you will see only a big picture of the same size graph. But here the purpose is to zoom-in the graph and see every small details in it which might have got hidden because of this size of the graph.<\/p>\n

Explanation of VBA Code used to build this<\/h1>\n

Read carefully all the comments which I have provided in the below codes. They are easy to understand like what each and every statement of VBA code is doing? What is the use of them. If you still have any doubt or question or suggestion.. feel free to let me know by commenting your question in the comment section below:<\/p>\n

\r\nPublic tempFileName\r\nSub Zoom_Chart()\r\n\r\nDim i As Integer\r\nDim strChartName As String\r\nDim dZoomInWidth As Double\r\nDim dZoomInHeight As Double\r\nDim dOutWidth As Double\r\nDim dOutHeight As Double\r\nDim rngZoom As Range\r\nDim rngChart As Range\r\n         \r\n        dZoomInWidth = ActiveSheet.[rngZoomWidth].Value '<-THIS CAN BE CHANGED\r\n        dZoomInHeight = ActiveSheet.[rngZoomHeight].Value '<-THIS CAN BE CHANGED\r\n        dOutWidth = 1 \/ dZoomInWidth 'zooms back to original size\r\n        dOutHeight = 1 \/ dZoomInHeight\r\n    '-----------------------------------------------------------------------------------\r\n    'Set the button\/shape name based on the shape that was clicked by the user\r\n    strChartName = Application.Caller\r\n    tempFileName = VBA.Environ$("Temp") & "\\zoomGraph.gif"\r\n    'Set range of zoom button for intersection check\r\n    Set rngZoom = Range(ActiveSheet.Shapes(strChartName).TopLeftCell.Address)\r\n    With ActiveSheet\r\n            Set rngChart = Range(.Shapes(strChartName).TopLeftCell.Address)\r\n                If ActiveSheet.Shapes(strChartName).Type = msoChart Then\r\n                With ActiveSheet.Shapes(strChartName)\r\n                        Application.ScreenUpdating = False\r\n                        .ZOrder msoBringToFront\r\n                        dashboard.Unprotect password:="Vishwa@123"\r\n                        .ScaleWidth dZoomInWidth, msoFalse, msoScaleFromTopLeft\r\n                        .ScaleHeight dZoomInHeight, msoFalse, msoScaleFromTopLeft\r\n                        .Chart.Export Filename:=tempFileName, FilterName:="GIF"\r\n                        .ScaleWidth dOutWidth, msoFalse, msoScaleFromTopLeft\r\n                        .ScaleHeight dOutHeight, msoFalse, msoScaleFromTopLeft\r\n                        dashboard.Protect password:="Vishwa@123"\r\n                        zoomForm.Show\r\n                        ActiveSheet.Shapes(strChartName).ZOrder msoBringToFront\r\n                        'Kill the temp file now\r\n                        Kill tempFileName\r\n                End With\r\n                End If\r\n    End With\r\nEnd Sub\r\n<\/code><\/pre>\n

How does it look after creating this<\/h1>\n

On clicking on graph this is how you see graph based on the % provided about height and width for the Zoom.
\n

\"Graph-Zoom-in-Zoom-Out-button\"<\/a>

Graph-Zoom-in-Zoom-Out-button<\/p><\/div><\/p>\n

Download FREE Copy to Play around<\/h1>\n

I have created one sample Excel file with such Zoom-in and Zoom-out feature. You can download it and play around.. Happy excel macro learning \ud83d\ude42
\n<\/p>\n<\/span>","protected":false},"excerpt":{"rendered":"

Hello Friends, How are you doing? I am back with my next article about “how to make a button to zoom-in and zoom-out a graph in Excel VBA”. this is the second method I am going to explain you. In my previous article, I had explained about the very basic method. There were 4 limitations […]<\/p>\n","protected":false},"author":45,"featured_media":13978,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1679,1675,1676,1678],"tags":[],"yoast_head":"\nZoom in and Zoom out button for a Chart in Excel \u2013 [Method 2]<\/title>\n<meta name=\"description\" content=\"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Button to Zoom in a Graph in Excel - [Method 2]\" \/>\n<meta property=\"og:description\" content=\"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013\" \/>\n<meta property=\"og:url\" content=\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\" \/>\n<meta property=\"og:site_name\" content=\"Let's excel in Excel\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:author\" content=\"http:\/\/www.facebook.com\/vmlogger\" \/>\n<meta property=\"article:published_time\" content=\"2016-10-07T18:40:24+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-22T16:38:19+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/07\/Zoom-graph-in-excel-3.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"538\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Vishwamitra Mishra\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/www.twitter.com\/learnexcelmacro\" \/>\n<meta name=\"twitter:site\" content=\"@learnexcelmacro\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Vishwamitra Mishra\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\"},\"author\":{\"name\":\"Vishwamitra Mishra\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"headline\":\"Button to Zoom in a Graph in Excel – [Method 2]\",\"datePublished\":\"2016-10-07T18:40:24+00:00\",\"dateModified\":\"2017-11-22T16:38:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\"},\"wordCount\":476,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"articleSection\":[\"Excel Macro Beginner\",\"Excel Macro Tutorial\",\"Excel Tips\",\"Interesting VBA Functions\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\",\"name\":\"Zoom in and Zoom out button for a Chart in Excel \u2013 [Method 2]\",\"isPartOf\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\"},\"datePublished\":\"2016-10-07T18:40:24+00:00\",\"dateModified\":\"2017-11-22T16:38:19+00:00\",\"description\":\"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013\",\"breadcrumb\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/vmlogger.com\/excel\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Excel Macro Beginner\",\"item\":\"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Button to Zoom in a Graph in Excel – [Method 2]\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#website\",\"url\":\"https:\/\/vmlogger.com\/excel\/\",\"name\":\"Let's excel in Excel\",\"description\":\"Let's share knowledge\",\"publisher\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/vmlogger.com\/excel\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5\",\"name\":\"Vishwamitra Mishra\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"contentUrl\":\"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png\",\"width\":528,\"height\":560,\"caption\":\"Vishwamitra Mishra\"},\"logo\":{\"@id\":\"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/\"},\"description\":\"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.\",\"sameAs\":[\"http:\/\/www.learnexcelmacro.com\",\"http:\/\/www.facebook.com\/vmlogger\",\"https:\/\/twitter.com\/https:\/\/www.twitter.com\/learnexcelmacro\",\"https:\/\/www.youtube.com\/c\/VMLogger\"],\"url\":\"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Zoom in and Zoom out button for a Chart in Excel \u2013 [Method 2]","description":"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/","og_locale":"en_US","og_type":"article","og_title":"Button to Zoom in a Graph in Excel - [Method 2]","og_description":"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013","og_url":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/","og_site_name":"Let's excel in Excel","article_publisher":"http:\/\/www.facebook.com\/vmlogger","article_author":"http:\/\/www.facebook.com\/vmlogger","article_published_time":"2016-10-07T18:40:24+00:00","article_modified_time":"2017-11-22T16:38:19+00:00","og_image":[{"width":800,"height":538,"url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2017\/07\/Zoom-graph-in-excel-3.jpg","type":"image\/jpeg"}],"author":"Vishwamitra Mishra","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/www.twitter.com\/learnexcelmacro","twitter_site":"@learnexcelmacro","twitter_misc":{"Written by":"Vishwamitra Mishra","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#article","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/"},"author":{"name":"Vishwamitra Mishra","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"headline":"Button to Zoom in a Graph in Excel – [Method 2]","datePublished":"2016-10-07T18:40:24+00:00","dateModified":"2017-11-22T16:38:19+00:00","mainEntityOfPage":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/"},"wordCount":476,"commentCount":1,"publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"articleSection":["Excel Macro Beginner","Excel Macro Tutorial","Excel Tips","Interesting VBA Functions"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/","url":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/","name":"Zoom in and Zoom out button for a Chart in Excel \u2013 [Method 2]","isPartOf":{"@id":"https:\/\/vmlogger.com\/excel\/#website"},"datePublished":"2016-10-07T18:40:24+00:00","dateModified":"2017-11-22T16:38:19+00:00","description":"How to create Zoom-in excel Chart button and Zoom-out excel Chart button using Excel VBA code. Refer the other article to create a button to Zoom in a Graph in Excel \u2013","breadcrumb":{"@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/vmlogger.com\/excel\/2016\/10\/button-to-zoom-in-a-graph-in-excel-method-2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/vmlogger.com\/excel\/"},{"@type":"ListItem","position":2,"name":"Excel Macro Beginner","item":"https:\/\/vmlogger.com\/excel\/excel-macro-beginner\/"},{"@type":"ListItem","position":3,"name":"Button to Zoom in a Graph in Excel – [Method 2]"}]},{"@type":"WebSite","@id":"https:\/\/vmlogger.com\/excel\/#website","url":"https:\/\/vmlogger.com\/excel\/","name":"Let's excel in Excel","description":"Let's share knowledge","publisher":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/vmlogger.com\/excel\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/7500a107b0b2d35a8492acf0d11fc8e5","name":"Vishwamitra Mishra","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/","url":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","contentUrl":"https:\/\/vmlogger.com\/excel\/wp-content\/uploads\/sites\/11\/2022\/07\/avataaars-1.png","width":528,"height":560,"caption":"Vishwamitra Mishra"},"logo":{"@id":"https:\/\/vmlogger.com\/excel\/#\/schema\/person\/image\/"},"description":"My name is Vishwamitra Mishra. Friends Call me Vishwa. I hold a Bachelor\u2019s Degree in Computer Science from D.A.V.V. Indore & currently working as a Technical Lead having over 7 years of experience.","sameAs":["http:\/\/www.learnexcelmacro.com","http:\/\/www.facebook.com\/vmlogger","https:\/\/twitter.com\/https:\/\/www.twitter.com\/learnexcelmacro","https:\/\/www.youtube.com\/c\/VMLogger"],"url":"https:\/\/vmlogger.com\/excel\/author\/vishwamitra\/"}]}},"_links":{"self":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4682"}],"collection":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/users\/45"}],"replies":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/comments?post=4682"}],"version-history":[{"count":0,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/posts\/4682\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media\/13978"}],"wp:attachment":[{"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/media?parent=4682"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/categories?post=4682"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vmlogger.com\/excel\/wp-json\/wp\/v2\/tags?post=4682"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}