<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">

    <title type="text">Excel Blog</title>
    <subtitle type="text">Excel Blog:Spreadsheet Modeling and Related Topics.</subtitle>
    <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/index/" />
    <link rel="self" type="application/atom+xml" href="http://www.cellmatrix.net/index.php/site/atom/" />
    <updated>2010-03-07T13:28:48Z</updated>
    <rights>Copyright (c) 2010, jfm</rights>
    <generator uri="http://www.pmachine.com/" version="1.6.8">ExpressionEngine</generator>
    <id>tag:cellmatrix.net,2010:02:23</id>


    <entry>
      <title>Add an ActiveX SpinButton Control to a Spreadsheet</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/add_an_activex_spinbutton_control_to_a_spreadsheet/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.255</id>
      <published>2010-02-23T12:30:55Z</published>
      <updated>2010-02-24T05:18:56Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="VBA"
        scheme="http://www.cellmatrix.net/index.php/site/category/VBA/"
        label="VBA" />
      <content type="html"><![CDATA[
        <p>One of my favorite tools for controlling the input to a single cell within an interactive spreadsheet model is an ActiveX SpinButton.  When added to a spreadsheet, the SpinButton can allow the user to move quickly through multiple scenarios within a predefined range of values.</p>  

<p>In Excel 2007, you can add an ActiveX SpinButton to a spreadsheet by first selecting the Developer tab.  Then select Insert -> ActiveX Controls -> Spin Button.</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2010220101.bmp" style="border: 0;" alt="image" width="633" height="379" />
</div>

<p>In Design mode, you can link a cell as well as adjust the minimum and maximum values for the SpinButton.  To do so, click on the SpinButton when in design mode.  Then right-click on your mouse to access the properies for that SpinButton.</p>

<p>Rather than manually entering the minimum, maximum, and linked cell properties, my personal preference is to use a few simple VBA statements.  For example, assuming the SpinButton is named "SpinButton1", to add a maximum value = 30, a minimum value = 20, and a linked cell = C4, and an incremental value = 1, add the following code to the sheet module for the sheet containing the ActiveX SpinButton.</p> 

<pre>
Private Sub SpinButton1_SpinDown()
    With Range("C4")
        .Value = WorksheetFunction.Max(20, .Value - 1)
    End With
End Sub

Private Sub SpinButton1_SpinUp()
    With Range("C4")
        .Value = WorksheetFunction.Min(30, .Value + 1)
    End With
End Sub
</pre>

<p>The cell entry for the SpinButton combined with the SpinButton Control might be set up on the spreadsheet to look like this:</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2010220102.bmp" style="border: 0;" alt="image" width="322" height="125" />
</div>

<p>To allow the SpinButton to accept changes in percent, slightly modify the code above.  For example, to add a maximum value = .50, a minimum value = .30, and a linked cell = C4, and an incremental value = .01, add the following code to the sheet module for the sheet containing the ActiveX SpinButton.</p>

<pre>
Private Sub SpinButton1_SpinDown()
    With Range("C4")
        .Value = WorksheetFunction.Max(0.3, .Value - 0.01)
    End With
End Sub

Private Sub SpinButton1_SpinUp()
    With Range("C4")
        .Value = WorksheetFunction.Min(0.5, .Value + 0.01)
    End With
End Sub
</pre>

<p>After changing the cell entry number format to percent, for the SpinButton combined with the SpinButton Control might be set up on the spreadsheet to look like this:</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2010220103.bmp" style="border: 0;" alt="image" width="322" height="125" />
</div>

<p>Although you must be in design mode to modify the size and position of the SpinButton and /or modify its properties, you must exit the design mode in order for the SpinButton to be operable.</p>  

<p>Note: the examples above are based on code and techniques that can be found at the following:</p>
<ul>
<li>From java2s.com:  <a href="http://www.java2s.com/Code/VBA-Excel-Access-Word/Forms/Spinupeventprocedureforspinbutton.htm" title="SpinUp Events">SpinUp Events</a></li>
<li>From java2s.com:  <a href="http://www.java2s.com/Code/VBA-Excel-Access-Word/Forms/ThespinbuttoncontrolusestheSpinDownandSpinUpeventstodecreaseandincreasethevalueincellB4.htm" title="SpinDown Events">SpinDown Events</a></li>
<li>From Microsoft:  <a href="http://office.microsoft.com/en-us/excel/HP102366821033.aspx" title="Add a Scroll Bar or Spin Button to a Worksheet">Add a Scroll Bar or Spin Button to a Worksheet</a></li>
<li><a href="http://spreadsheetpage.com/index.php/book/excel_2007_power_programming_with_vba/" title="Excel 2007 Power Programming with VBA">Excel 2007 Power Programming with VBA</a> by John Walkenbach - Chapter 13 - Pages 440 - 442.</li>
<li>Excel 2000 VBA by John Green - Chapter 10 - page 175.</li>
</ul>

<br/> 
      ]]></content>
    </entry>

    <entry>
      <title>Excel 2010 Chart Improvements &#45; Migrating Excel 4 Macros to VBA</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/excel_2010_chart_improvements_-_migrating_excel_4_macros_to_vba/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.254</id>
      <published>2010-02-19T11:56:12Z</published>
      <updated>2010-02-20T11:38:13Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Charts"
        scheme="http://www.cellmatrix.net/index.php/site/category/Charts/"
        label="Charts" />
      <content type="html"><![CDATA[
        <p>From the <a href="http://blogs.msdn.com/excel/archive/2010/02/16/migrating-excel-4-macros-to-vba.aspx" title="Microsoft Excel Product Team Blog">Microsoft Excel Product Team Blog</a> . . .</p> 

<p><i>There are a number of properties for chart elements that were previously only accessible through the Excel 4 Macro Language. We have added additional properties to VBA for these items.</i></p>

<p><b>Formula Properties</b> - <i>New properties replace the GET.FORMULA() XLM command, providing formula support for missing chart elements. New Formula properties (Formula, FormulaR1C1, FormulaLocal, FormulaR1C1Local) have been added for AxisTitle, ChartTitle, DisplayUnitLabel, and DataLabel objects.</i></p>

<p><b>Series/Point Name</b> - <i>The chart object model currently doesn’t provide a way to determine the series name that is given to a series when it is created. This information is available when hovering over a data point with the mouse, or using the SELECTION() function in XLM. The XLM command returns a point name in the format “SmPn” where m is the series number assigned when the chart is created and n is the point number. For example, when selecting a point on a chart, SELECTION() returns "S1P3". A new Point.Name property has been added that Returns a point name in the format “SmPn” where m is the series number assigned when the chart is created and n is the point number.</i></p> 

<p><b>Position Properties</b> - <i>The XLM Function GET.CHART.ITEM returns the X,Y coordinates of the corners or mid-points of any chart item. This function had been necessary for some chart elements that did not have positional (.Left, .Top, .Width, and .Height) properties. In Excel 2010 we added .Left, .Top, .Width, and .Height properties for any chart elements that did not have them. This included AxisTitle, ChartTitle, DisplayUnitLabel, Point, and DataLabel objects. Additionally we added a Point.PieSliceLocation Method that returns coordinates of multiple points on Pie Slices.</i></p>

<br/>
 
      ]]></content>
    </entry>

    <entry>
      <title>RefEdit Entries</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/refedit_entries/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.252</id>
      <published>2010-02-16T11:47:32Z</published>
      <updated>2010-02-16T12:38:33Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="VBA"
        scheme="http://www.cellmatrix.net/index.php/site/category/VBA/"
        label="VBA" />
      <content type="html"><![CDATA[
        <p>Recently I've been working on creating a ribbon tab for Excel 2007 that interfaces with and controls several of the add-ins that I use for work.  The  
<a href="http://www.cellmatrix.net/index.php/excel/comments/goal_seek_tool/" title="Goal Seek Tool">Goal Seek Tool</a> is one of those add-ins.  I created this tool to allow the  entry of a single-cell range or value when performing the goal-seek function.</p>

<p>In November 2008 I wrote a short post about my Goal Seek tool.  In my first version of that tool, I used a RefEdit control to enter a range and a textbox to enter a value.  In a comment to that post, <a href="http://peltiertech.com/" title="Jon Peltier">Jon Peltier</a> noted that the textbox could be eliminated and the RefEdit control could be programmed to accept either a range or text entry.</p>

<p>After a lot of time searching the internet, I finally found an example of how this functionality could work on the <a href="http://www.tushar-mehta.com/" title="TM Consulting ">TM Consulting</a> site.  It looks like this:</p>

<p>When wanting to enter a range with RefEdit and assuming the RefEdit control is named "RefEdit1", use</p>

<pre>
Range(RefEdit1) 
</pre>  

<p>When wanting to enter a value with RefEdit, use</p>

<pre>
Range(RefEdit1).value 
</pre>  

<p>When wanting to validate the entries made into RefEdit, you can use examples like:</p>

<p>To validate that a range contains a formula, use</p>

<pre>
HasFormula(Range(RefEdit1)) 
</pre>  

<p>To validate that a range contains a number, use</p>

<pre>
IsNumeric(RefEdit1)
</pre>  

<br/>

 
      ]]></content>
    </entry>

    <entry>
      <title>VBA Fireworks Model from AJP Excel Information</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/vba_fireworks_model_from_ajp_excel_information/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.250</id>
      <published>2010-01-28T11:33:09Z</published>
      <updated>2010-01-28T12:11:10Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="VBA"
        scheme="http://www.cellmatrix.net/index.php/site/category/VBA/"
        label="VBA" />
      <content type="html"><![CDATA[
        <p>Recently I had the opportunity to build Andy Pope's <a href="http://www.andypope.info/fun/fireworks.htm" title="fireworks display">fireworks display</a> into a line chart that I produce each month.  Fireworks were requested because 2009 was the best year on record for a particular business unit at work.  When I presented the operating results the animation was a big hit.</p>  

<p>Once you download the file you'll find that Andy's display utilizes an XY Scatter chart and VBA code with trigonometry functions to produce the fireworks.  Because the code is unprotected you can easily load the modules into your own project and then customize the code as you wish.  Even if you don't have an interest in using the display, the file is worth downloading just to study how the model was developed.  Thanks Andy for making this available.</p>        
      ]]></content>
    </entry>

    <entry>
      <title>Turn off Automatic Hyperlinks</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/turn_off_automatic_hyperlinks/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.247</id>
      <published>2010-01-17T14:44:26Z</published>
      <updated>2010-01-17T15:18:27Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="General"
        scheme="http://www.cellmatrix.net/index.php/site/category/General/"
        label="General" />
      <content type="html"><![CDATA[
        <p>Does it annoy you when Excel automatically turns an email or web address into a hyperlink when you want it entered as text?  In Excel 2007 you can prevent this from happening by clicking on the Office button and going to Excel Options -> Proofing -> Deselect the option titled "Ignore Internet and file addresses".</p>

<p>The <a href="http://spreadsheetpage.com/" title="The Spreadsheet Page">The Spreadsheet Page</a> has a tip titled <a href="http://spreadsheetpage.com/index.php/tip/removing_or_avoiding_automatic_hyperlinks/" title="Removing or Avoiding Automatic Hyperlinks">Removing or Avoiding Automatic Hyperlinks</a> that covers this very topic.  The tip provides the following macro which will allow you to instantly turn all of your hyperlinks into text.  The macro really helped me as I had a sheet with over 100 links to zap.</p>

<pre>
Sub ZapHyperlinks() 
    Cells.Hyperlinks.Delete
End Sub
</pre>

<p>As I'm just making the switch from Excel 2003 to 2007 it made me think . . . what features do Excel users automatically turn on or off when moving to a different version?  Understanding that everyone has their own preferences, I'd like to hear about those features that are a "must have" or that you immediately shut off.</p>  

<br/>

 
      ]]></content>
    </entry>

    <entry>
      <title>VBA Array to Change Line Chart Colors</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/vba_array_to_change_line_chart_colors/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.246</id>
      <published>2010-01-11T11:00:34Z</published>
      <updated>2010-01-10T13:58:35Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Charts"
        scheme="http://www.cellmatrix.net/index.php/site/category/Charts/"
        label="Charts" />
      <content type="html"><![CDATA[
        <p>Part of my responsibilities at work is building the end-of-month financial packet that is presented to management.  That packet includes a variety of line charts that show trends in financial and statistical metrics.  Many of the graphs start with a base year and require adding an additional line as the year turns over.  For example, in 2009 and given a base year of 2006 each line chart would have five lines (2006, 2007, 2008, 2009 plan, and 2009 actual).  Now that the year has turned over, each graph will have six lines (2006, 2007, 2008, 2009, 2010 plan, and 2010 actual).</p>

<p>This may or may not be the most efficient process, but I prefer to keep the line series order as follows:</p>

<ul>
<li>Series 1 = Current Year (2010) -> line color = red</li>
<li>Series 2 = Current Year Plan (2010) -> line color = blue</li>
<li>Series 3 = Prior Year (2009) -> line color = green</li>
<li>Series 4 = Prior Year - 1 (2008) -> line color = silver</li>
<li>Series 5 = Prior Year - 2 (2007) -> line color = silver</li>
<li>Series 6 = Prior Year - 3 (2006) -> line color = silver</li>
</ul>  

<p>This logic can present a problem in that as an additional series is added, the series order needs to be renumbered and the line colors have to be redone.  To make the process easier, we use the following macro to change the series colors.  It uses an array to store the color index numbers for each series.</p>

<pre>
Sub Color_Series()

    Dim arrColors(1 To 6) As Integer
    
    Dim Cht As ChartObject
    
    Dim i As Integer
     
    arrColors(1) = 3    'Series 1 - Red = Current Year (2010)
    arrColors(2) = 5    'Series 2 - Blue = Current Year Plan (2010)
    arrColors(3) = 10  'Series 3 - Green = Prior Year (2009)
    arrColors(4) = 16  'Series 4 - Silver = Prior Year (2008)
    arrColors(5) = 15  'Series 5 - Silver = Prior Year (2007)
    arrColors(6) = 14  'Series 6 - Silver = Prior Year (2006)
    
    Set Cht = Worksheets("Sheet1").ChartObjects("Chart01")
    
    For i = LBound(arrColors) To UBound(arrColors)
    
        Cht.Chart.SeriesCollection(i).Border.ColorIndex = arrColors(i)
        
    Next i
    
End Sub
</pre> 

<p>Rather than looping through an array, you could just as easily refer to each of the series individually.  To do so, the code would look like this:</p>

<pre>
Sub Color_Series()

    Dim Cht As ChartObject
    
    'Series 1 - ColorIndex = 3 = Red = Current Year (2010)
    'Series 2 - ColorIndex = 5 = Blue = Current Year Plan (2010)
    'Series 3 - ColorIndex = 10 = Green = Prior Year (2009)
    'Series 4 - ColorIndex = 16 = Silver = Prior Year (2008)
    'Series 5 - ColorIndex = 15 = Prior Year (2007)
    'Series 6 - ColorIndex = 14 = Silver = Prior Year (2006)
    
    Set Cht = Worksheets("Sheet1").ChartObjects("Chart01")
    
    Cht.Chart.SeriesCollection(1).Border.ColorIndex = 3
    Cht.Chart.SeriesCollection(2).Border.ColorIndex = 5
    Cht.Chart.SeriesCollection(3).Border.ColorIndex = 10
    Cht.Chart.SeriesCollection(4).Border.ColorIndex = 16
    Cht.Chart.SeriesCollection(5).Border.ColorIndex = 15
    Cht.Chart.SeriesCollection(6).Border.ColorIndex = 16
        
End Sub
</pre> 

<br/>

 
      ]]></content>
    </entry>

    <entry>
      <title>VBA Function to Screen for Certain Charts</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/vba_function_to_screen_for_certain_charts/" />
      <id>tag:cellmatrix.net,2010:index.php/site/index/1.244</id>
      <published>2010-01-08T11:10:41Z</published>
      <updated>2010-01-08T12:15:42Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Charts"
        scheme="http://www.cellmatrix.net/index.php/site/category/Charts/"
        label="Charts" />
      <content type="html"><![CDATA[
        <p>Until late last year I've primarily worked with Excel 2003 because that's what we use at work.  However, that changed over the holidays because my home computer crashed and the new one came with Excel 2007.  I was trying to wait until Excel 2010 was available before buying a new computer but the old machine just couldn't make it that long.</p>

<p>It seems like most of what I've read regarding the Excel 2007 ribbon has been negative.  However, after using Excel 2007 for a couple of weeks my initial impressions are that I like it.  Although the ribbon can't be modified as easy as the toolbars were in previous versions, having the ability to create your own ribbon tabs makes up for that problem for me.  And having the ability to customize the quick access toolbar makes up for inefficiencies in the placement of the ribbon commends.</p>

<p>Now that I've made the move to 2007, I need to rebuild several add-ins that I've created to interface with the ribbon.  One of the add-ins that I've created is for working with embedded charts only.  Built into that add-in is a function written by <a href="http://spreadsheetpage.com/" title="John Walkenbach">John Walkenbach</a> that alerts the user if he or she failed to select a chart.  After screening for a chart selection, I've added a second chart-screening function that utilizes a case statement to alert the user if an "improper" chart type is selected.  In the example, an improper chart is by my definition only.  That second chart-screening function follows:</p>

<p>First, declare an optional public variable containing the name of the application (add-in).</p>

<pre>
Option Explicit
Public Const APPNAME As String = "Position Chart Labels"
</pre>

<p>Next, provide the code that triggers the user form.  "ValidContext" references the chart screening function below.</p>

<pre>
Sub MoveChartLabels()
    If ValidContext(True) Then frmMoveLabels.Show
End Sub
</pre>

<p>Finally, provide the chart screening function.  If the chart type appears as a line in the code below the function considers the chart to be valid.  If not, the function kicks out an error message.  The function works with combination charts because it evaluates each individual chart series for the accepted chart type.</p>

<pre>
Private Function ValidContext(ChtType) As Boolean
   
    Dim Sr As Series
    Dim Srs As SeriesCollection
    
    Const MsgChtType As String = "Invalid chart type."
        
    Set Srs = ActiveChart.SeriesCollection
    
    For Each Sr In Srs
     
        Select Case Sr.ChartType
            
            'Accepted Line Charts
            Case xlLine: ValidContext = True
            Case xlLineStacked: ValidContext = True
            Case xlLineStacked100: ValidContext = True
            Case xlLineMarkers: ValidContext = True
            Case xlLineMarkersStacked: ValidContext = True
            Case xlLineMarkersStacked100: ValidContext = True
            
            'Accepted Column Charts
            Case xlColumnClustered: ValidContext = True
            Case xlColumnStacked: ValidContext = True
            Case xlColumnStacked100: ValidContext = True
        
            'Accepted Bar Charts
            Case xlBarClustered: ValidContext = True
            Case xlBarStacked: ValidContext = True
            Case xlBarStacked100: ValidContext = True
                    
            'Accepted Area Charts
            Case xlArea: ValidContext = True
            Case xlAreaStacked: ValidContext = True
            Case xlAreaStacked100: ValidContext = True
            
            'Accepted XY Scatter Charts
            Case xlXYScatter: ValidContext = True
            Case xlXYScatterSmooth: ValidContext = True
            Case xlXYScatterSmoothNoMarkers: ValidContext = True
            Case xlXYScatterLines: ValidContext = True
            Case xlXYScatterLinesNoMarkers: ValidContext = True
    
            'Accepted Pie Charts
            Case xlPie: ValidContext = True
            Case xlPieExploded: ValidContext = True
            Case xlPieOfPie: ValidContext = True
            Case xlBarOfPie: ValidContext = True
            
            Case Else
                ValidContext = False
                MsgBox MsgChtType, vbCritical, APPNAME
                Exit Function
        
        End Select

    Next Sr
    
End Function
</pre>

<br/> 
      ]]></content>
    </entry>

    <entry>
      <title>VBA for Adding and Deleting Data Labels</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/vba_for_adding_and_deleting_data_labels/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.238</id>
      <published>2009-12-22T09:03:45Z</published>
      <updated>2009-12-22T09:49:46Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Charts"
        scheme="http://www.cellmatrix.net/index.php/site/category/Charts/"
        label="Charts" />
      <content type="html"><![CDATA[
        <p>I'm currently working on a project where I have multiple embedded line charts in a workbook.  Each line chart contains any number of multiple series.  Each series contains 12 points representing each month of the year.  For each chart I need to show the data points for the current month only.</p>

<p>Although the combination Line - XY Scatter chart works, I want to use VBA to add and delete the data labels in each chart in an effort to minimize the number of chart series that the owner of the workbook needs to maintain.  Below are some simple macros for adding and deleting data labels that I've used for reference and / or utilized in my project.  Each example works for the active chart only (an active single embedded chart).</p> 

<p>To delete a label from a single series:</p>

<pre>
Sub Delete_Labels_From_A_Single_Series()
    For Each X In ActiveChart.SeriesCollection(1).Points
        X.DataLabel.Delete
    Next X
End Sub
</pre>

<p>A second method for deleting a label from a single series:</p>

<pre>
Sub Delete_Labels_From_A_Single_Series()
    
    Dim Cht As Chart
    Dim Srs As Series
    
    Set Cht = ActiveChart
    Set Srs = Cht.SeriesCollection(1)
    
        With Srs
            If .HasDataLabels Then .DataLabels.Delete
        End With

End Sub
</pre>

<p>To add data labels to multiple series at one time:</p>

<pre>
Sub Add_Data_Labels_To_All_Series()
    
    Dim Cht As Chart
    
    Set Cht = ActiveChart
    
    For Each Sr In Cht.SeriesCollection
        Sr.ApplyDataLabels
        Sr.DataLabels.ShowValue = True
        Sr.DataLabels.Position = xlLabelPositionAbove
    Next Sr

End Sub
</pre>

<p>To delete data labels from multiple series at one time:</p>

<pre>
Sub Delete_Data_Labels_From_All_Series()
    
    Dim Cht As Chart
    
    Set Cht = ActiveChart
    
    For Each Sr In Cht.SeriesCollection
        If Sr.HasDataLabels Then Sr.DataLabels.Delete
    Next Sr

End Sub
</pre>

<br/>






 
      ]]></content>
    </entry>

    <entry>
      <title>Removing Spaces from File Names</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/removing_spaces_from_file_names/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.237</id>
      <published>2009-11-19T10:25:12Z</published>
      <updated>2009-11-19T10:49:13Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="VBA"
        scheme="http://www.cellmatrix.net/index.php/site/category/VBA/"
        label="VBA" />
      <content type="html"><![CDATA[
        <p>For a number of reasons I prefer to never use spaces in file names.  Recently Dick Kuslieka at the <a href="http://www.dailydoseofexcel.com/" title="Daily Dose of Excel">Daily Dose of Excel</a> posted an interesting VBA technique for <a href="http://www.dailydoseofexcel.com/archives/2009/11/12/removing-spaces-from-file-names/" title="removing spaces from file names">removing spaces from file names</a>.  John Walkenbach commented with a revision that will allow the same functionality using Excel 2007 and Rick Rothstein commented with another alternative.   These snippets are great additions to my VBA toolbox.</p>

<p>Dick's Kuslieka's original post:</p>

<pre>
Sub RemoveSpaces()
    
    Dim fso As FileSystemObject
    Dim fsoFile As File
    
    Set fso = New FileSystemObject
    
    For Each fsoFile In fso.GetFolder("C:\Tester").Files
        If InStr(1, fsoFile.Name, " ")> 0 Then
            fsoFile.Name = Replace(fsoFile.Name, " ", "_")
        End If
    Next fsoFile
    
End Sub
</pre>

<p>John Walkenbach's version for Excel 2007:</p>

<pre>
Sub RemoveSpaces()
    Const Folder As String = "C:\Tester\"
    Dim FileName As String, NewName As String
    FileName = Dir(Folder)
    Do While FileName  ""
        If InStr(1, FileName, " ")&gt; 0 Then
            NewName = Replace(FileName, " ", "_")
            Name Folder &amp; FileName As Folder &amp; NewName
        End If
        FileName = Dir
    Loop
End Sub
</pre>

<p>and Rick Rothstein commented with another version:</p>

<pre>
Sub RemoveSpaces()
  Dim Path As String, FileName As String
  Path = "C:\Tester\"  'Note the trailing backslash
  FileName = Dir(Path &amp; "*.*")
  Do While FileName  ""
    Name Path &amp; FileName As Path &amp; Replace(FileName, " ", "_")
    FileName = Dir
  Loop
End Sub
</pre>

<br/>

 
      ]]></content>
    </entry>

    <entry>
      <title>Arrays to Calculate Consistent Increases in Rate Spreads</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/arrays_to_calculate_consistent_increases_in_rate_spreads/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.236</id>
      <published>2009-11-14T14:47:05Z</published>
      <updated>2009-11-14T20:07:06Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Modeling"
        scheme="http://www.cellmatrix.net/index.php/site/category/modeling/"
        label="Modeling" />
      <content type="html"><![CDATA[
        <p>Every year at work we go through a planning cycle for the following year.  During that time we build an annual and five year plan.  After those plans are approved and submitted, we revisit the annual plan and spread those results across each month of the year.  We then do a second submission of monthly results.</p>

<p>In going through that process, I've struggled to explain why the following calculation doesn't work . . .</p>

<p>In the example below we're given the total planned 2010 volume (in the yellow cell) that we need to spread.  The spread needs to be based on a consistent or even growth in the rate per work day.  We have history for volume in 2009 and workdays for 2009 and 2010 as well.  Below is a screenshot of what we know.</p>    
  
<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2009111401.gif" style="border: 0;" alt="image" width="494" height="155" />
</div>

<br/>

<p>On the surface this seems to be a simple algebra problem.  Knowing the total planned volume for 2010 and having 2009 as a base, the spread should be an easy calculation using the 6-month average volume per workday.</p>

<p>Using this logic, the calculation above now looks like this:</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2009111402.gif" style="border: 0;" alt="image" width="494" height="227" />
</div>

<br/>

<p>In the range J12:J14, a rate per workday has been calculated for both years.  The change in the rate is applied to each month (range D12:I14).  Finally, the 2010 rate per workday (range D13:I13) is multipled by the workdays (range D9:I9) to get the volume for each month (range D5:I5).</p>

<p>All of this seems to make sense until you sum the range D5:I5.  Instead of getting a total volume of 85,265, the actual total volume is 83,345.  The total volume is overstated by 80 units, or 0.09%.</p> 

<p>To correct this error, instead of using the increase in the total volume per workday and then applying that increase to each month, an array formula can be used.  Referencing the screenshot below:</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2009111403.gif" style="border: 0;" alt="image" width="494" height="225" />
</div>

<br/>

<p>the following array formula is entered into the green shaded range D13:I13 (using CNTL - SHIFT - ENTER at the same time to enter the array formula):</p>

<pre>
{=J5 / SUM((D4:I4)/(D8:I8)*(D9:I9)) * (D12:I12)}
</pre>

<p>Now when you sum the range D5:I5 the total volume ties to 85,265.  However, the monthly change in the rate is now 4.77% which does not agree with the 6-month average change of 4.87%.  The difference is due to how the array formula evaluates each individual month and then totals the results.</p>
 
<br/>




 


   
      ]]></content>
    </entry>

    <entry>
      <title>Show Gridlines when Filling an Interior Range</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/show_gridlines_when_filling_an_interior_range/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.233</id>
      <published>2009-10-29T11:53:00Z</published>
      <updated>2009-10-29T12:03:01Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="VBA"
        scheme="http://www.cellmatrix.net/index.php/site/category/VBA/"
        label="VBA" />
      <content type="html"><![CDATA[
        <p>Dick Kuslieka at the <a href="http://www.dicks-blog.com/" title="Daily Dose of Excel">Daily Dose of Excel</a> recently posted a macro that allows the user to <a href="http://www.dailydoseofexcel.com/archives/2009/10/28/borders-on-single-columns-or-single-rows/" title="create the illusion of gridlines">create the illusion of gridlines</a> when filling an interior worksheet range.  Thinking this a good addition to my Excel toolbox, I've copied it from Dick's site for reference.</p>

<pre>
Sub ColorRange()
    
    With Selection
        Selection.BorderAround xlContinuous, xlThin, , RGB(192, 192, 192)
        If .Columns.Count> 1 Then
            With .Borders(xlInsideVertical)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .Color = RGB(192, 192, 192)
            End With
        End If
        If .Rows.Count> 1 Then
            With .Borders(xlInsideHorizontal)
                .LineStyle = xlContinuous
                .Weight = xlThin
                .Color = RGB(192, 192, 192)
            End With
        End If
    End With
    
End Sub
</pre>

<br/> 
      ]]></content>
    </entry>

    <entry>
      <title>Delete All Embedded Charts from a Workbook</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/delete_all_embedded_charts_from_a_workbook/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.232</id>
      <published>2009-10-29T11:31:00Z</published>
      <updated>2009-10-29T11:51:01Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Charts"
        scheme="http://www.cellmatrix.net/index.php/site/category/Charts/"
        label="Charts" />
      <content type="html"><![CDATA[
        <p>Earlier this week a coworker approached me with a workbook that she needed help with.  Although the workbook appeared to contain only text values, it was prompting to update links every time it was opened.  Upon using Bill Manville's <a href="http://www.oaltd.co.uk/MVP/MVPPage.asp" title="FindLink Utility">FindLink Utility</a>, we were able to find links to embedded charts that had been hidden somewhere in the workbook.  Since she didn't need the charts, we used the following macro to delete all of the embedded charts in her workbook.</p>

<pre>
Sub Loop_Thru_Embedded_Chart_Objects()
    Dim Sht As Worksheet
    Dim ChtObj As ChartObject
    For Each Sht In ActiveWorkbook.Sheets
        For Each ChtObj In Sht.ChartObjects
            ChtObj.Delete
        Next ChtObj
    Next Sht
End Sub
</pre>

<br/> 
      ]]></content>
    </entry>

    <entry>
      <title>Formula Trace Tool for Excel 2007</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/formula_trace_tool_for_excel_2007/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.227</id>
      <published>2009-10-19T12:01:28Z</published>
      <updated>2009-10-19T12:37:29Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Add&#45;Ins"
        scheme="http://www.cellmatrix.net/index.php/site/category/Add-Ins/"
        label="Add&#45;Ins" />
      <content type="html"><![CDATA[
        <div class="imageright"><img src="http://www.cellmatrix.net/images/uploads/FTTButton.gif" style="border: 0;" alt="image" width="64" height="91" /></div>

<p>Last week I upgraded my formula auditing add-in to work with Excel 2007.  To recap, the Formula Trace Tool allows the auditor to click on precedent or dependent cell references in a listbox as opposed to clicking on audit arrows or performing a manual search.  The goal of this functionality is to allow the auditor to move through formulas much more quickly and efficiently.</p>

<p>When the add-in is installed, a button containing an orange diamond appears on the right side of the Formulas ribbon tab.  If interested, more information on how to use the tool and a link to download it <a href="http://www.cellmatrix.net/index.php/utilities/comments/formula_trace_tool" title="can be found here">can be found here</a>.</p>

<br/>

 
      ]]></content>
    </entry>

    <entry>
      <title>Stacking Embedded Charts</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/stacking_embedded_charts/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.222</id>
      <published>2009-10-12T01:35:35Z</published>
      <updated>2009-10-12T02:47:36Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="Modeling"
        scheme="http://www.cellmatrix.net/index.php/site/category/modeling/"
        label="Modeling" />
      <content type="html"><![CDATA[
        <p>A technique that I've found useful for presentations or working in small worksheet spaces involves stacking embedded charts on top of each other.  Stacking the charts is done in such a fashion that only one chart is visible at a time.  When a chart is needed, it is made visible by calling it to the top of the stack.</p>

<p>For example, start with four embedded charts on a worksheet named "charts":</p>  

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2009101101.gif" style="border: 0;" alt="image" width="505" height="337" />
</div>

<br/>

<p>First apply a name to each chart.  This is not required but in my experience I've found it's easier to keep track of chart names as opposed to numbers. This is especially true if you're constantly adding and deleting charts.  An easy way to name a chart is by activating it and then running the macro below.</p>

<pre>
Sub NameChart()
    ActiveChart.Parent.Name = "Cht01"
End Sub
</pre>

<p>I've named the charts in the screenshot "Cht01", "Cht02", "Cht03", and "Cht04".</p>

<p>Next, stack the charts one on top of another.  Again, a macro makes this easy.  The macro below sizes each chart to the size of the first chart (Cht01).  It then positions each chart into cell C2.</p>

<pre>
Sub StackCharts()

    Dim ChtObj As ChartObject
    Dim myCht As ChartObject
    Dim Rng As Range

    Set myCht = Worksheets("Charts").ChartObjects("Cht01")
    Set Rng = Worksheets("Charts").Range("C2")
    
    For Each ChtObj In ActiveSheet.ChartObjects

        ChtObj.Top = Rng.Top
        ChtObj.Left = Rng.Left
        ChtObj.Height = myCht.Height
        ChtObj.Width = myCht.Width

    Next ChtObj

End Sub
</pre>

<p>At this point only one chart is visible.  Finally, you can use controls to determine which chart is visible.  In the screenshot below I've added an option button for each chart.  Each option button contains code that makes the chart associated with it visible by bringing it to the top of the stack.  All four option buttons are grouped together.</p>

<p>The worksheet showing a single stacked group of charts with option button controls now looks like this:</p>

<div class="ctr">
<img src="http://www.cellmatrix.net/images/uploads/2009101102.gif" style="border: 0;" alt="image" width="305" height="296" />
</div>

<br/>

<p>Code now has to be added to each option button to control the position in the stack for the chart that it is associated with.  The code examples below need to be copied into the "charts" sheet module.</p>

<p>The code for the option button titled "Show Chart 1" is below:</p> 

<pre>
Private Sub OptionButton1_Click()
    Dim ChtObj As ChartObject
    Set ChtObj = Worksheets("Charts").ChartObjects("Cht01")
    ChtObj.ShapeRange.ZOrder msoBringToFront
End Sub
</pre>

<p>The code for the option button titled "Show Chart 2" is below:</p> 

<pre>
Private Sub OptionButton1_Click()
    Dim ChtObj As ChartObject
    Set ChtObj = Worksheets("Charts").ChartObjects("Cht02")
    ChtObj.ShapeRange.ZOrder msoBringToFront
End Sub
</pre>

<p>And so on for buttons three and four.</p>

<p>At this point the model is finished and the visibility of each chart is controlled by the option buttons.</p>

<br/>
 
      ]]></content>
    </entry>

    <entry>
      <title>Comment Shapes</title>
      <link rel="alternate" type="text/html" href="http://www.cellmatrix.net/index.php/site/comment_shapes/" />
      <id>tag:cellmatrix.net,2009:index.php/site/index/1.213</id>
      <published>2009-10-05T13:00:53Z</published>
      <updated>2009-10-11T17:20:54Z</updated>
      <author>
            <name>jfm</name>
            <email>john@cellmatrix.net</email>
                  </author>

      <category term="General"
        scheme="http://www.cellmatrix.net/index.php/site/category/General/"
        label="General" />
      <content type="html"><![CDATA[
        <p>Several sites have recently posted VBA techniques to add shapes to comments . . .</p>

<ul>
<li><a href="http://www.codeforexcelandoutlook.com/blog/2009/10/all-about-comment-shapes/" title="All About Comment Shapes">All About Comment Shapes</a> from the <a href="http://www.codeforexcelandoutlook.com/blog/" title="Code for Excel and Outlook Blog">Code for Excel and Outlook Blog</a>.</li>
<li><a href="http://chandoo.org/wp/2009/09/11/format-comment-box/" title="Pimp Your Comment Boxes">Pimp Your Comment Boxes</a> from <a href="http://chandoo.org/" title="Chandoo.org">Chandoo.org</a>.</li>
<li><a href="http://www.journalofaccountancy.com/Issues/2007/Jan/RemoveYourNameFromAnExcelComment" title="Remove Your Name From an Excel Comment">Remove Your Name From an Excel Comment</a> from the <a href="http://www.journalofaccountancy.com/" title="Journal of Accountancy">Journal of Accountancy</a>.</li>
<li><a href="http://www.contextures.com/xlcomments03.html" title="Comment Programming">Comment Programming</a> from <a href="http://www.contextures.com/" title="Contextures">Contextures</a>.</li>
</ul>

<br/> 
      ]]></content>
    </entry>


</feed>