<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>What a Palaver &#187; Excel</title>
	<atom:link href="http://whatapalaver.co.uk/category/geeky-corner/excel-geeky-corner-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://whatapalaver.co.uk</link>
	<description></description>
	<lastBuildDate>Wed, 25 Aug 2010 09:13:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Excel Pivot Table or CrossTab to Flat List</title>
		<link>http://whatapalaver.co.uk/2010/07/excel-pivot-table-or-crosstab-to-flat-list/</link>
		<comments>http://whatapalaver.co.uk/2010/07/excel-pivot-table-or-crosstab-to-flat-list/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 06:49:22 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[crosstab]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[flat list]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[Pivot Table]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://whatapalaver.co.uk/?p=1848</guid>
		<description><![CDATA[I often find myself struggling to deal with data that has been rendered almost unusable by the data provider who has converted it to a cross tab format. Usually they think they are helping and have probably started with a nice flat list then spent ages formatting it so the data spreads out across the [...]]]></description>
			<content:encoded><![CDATA[<p>I often find myself struggling to deal with data that has been rendered almost unusable by the data provider who has converted it to a cross tab format. Usually they think they are helping and have probably started with a nice flat list then spent ages formatting it so the data spreads out across the columns. Sometimes they have achieved this by putting the data into a pivot table but then have pasted the table as values and removed all links to the underlying data. Very helpful.</p>
<p> Yesterday I had to deal with a data file that looked a little like this only  it spread out across 455 columns and was frankly useless.</p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab1.gif"></a></p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2.gif"></a></p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2a.gif"><img class="size-full wp-image-1867  aligncenter" title="crosstab2a" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2a.gif" alt="" width="496" height="142" /></a></p>
<p style="text-align: left;">I wrote a post a while back that demonstrated <a href="http://whatapalaver.co.uk/2009/07/excel-crosstab-table-to-flat-list/">how to convert a simple cross tab back to a manageable data list</a> but I wanted to expand this with a slightly more complex example which had more field headings.</p>
<p>So starting with the table above which was probably a pasted copy from a pivot table I applied a little bit of formatting to achieve the following starting table.</p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2b.gif"><img class="aligncenter size-full wp-image-1868" title="crosstab2b" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2b.gif" alt="" width="519" height="149" /></a></p>
<p>What I have done is remove the grouping that the pivot table applies and ensured that I have the relevant  week number, project and department details against each name</p>
<p>I often wish to convert pivot table outputs back into a data file and the way I fill in the blanks caused by grouping data is to prepare a sheet with formulas that copy values from above (or the side as appropriate):</p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2c.gif"><img class="aligncenter size-full wp-image-1869" title="crosstab2c" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab2c.gif" alt="" width="472" height="166" /></a></p>
<p> </p>
<p>I then copy the pivot table data and then use the paste special command selecting paste values and skip blanks as the options.</p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/CROSSTAB1C.jpg"></a></p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab3.jpg"><img class="aligncenter size-full wp-image-1870" title="crosstab3" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab3.jpg" alt="" width="490" height="371" /></a>This results in the following output, which I then copy and paste over itself as values, to give me the desired structure.</p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab4.gif"><img class="aligncenter size-full wp-image-1871" title="crosstab4" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/crosstab4.gif" alt="" width="490" height="160" /></a></p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/CROSSTAB1B.jpg"></a></p>
<p>Having spent a bit of time on the structure of my starting file I can run the macro that will work through each row and transpose the data from a columnar layout to one based on rows.</p>
<p>The advantage of this format is that I can now create my own pivot tables and cut the data as I see fit to produce multiple summary formats according to my audience.</p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/CROSSTAB1C.jpg"></a></p>
<p style="text-align: center;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/FLATLIST.jpg"></a></p>
<p><span style="color: #000000;"><a href="http://whatapalaver.co.uk/wp-content/uploads/2010/07/flatlist1.gif"><img class="aligncenter size-full wp-image-1873" title="flatlist1" src="http://whatapalaver.co.uk/wp-content/uploads/2010/07/flatlist1.gif" alt="" width="505" height="577" /></a></span></p>
<p><span style="color: #000000;">Here&#8217;s the macro I use:</span></p>
<blockquote><p><strong>Sub CrossTabToList()</strong></p>
<p>Dim wsCrossTab As Worksheet<br />
Dim wsList As Worksheet<br />
Dim iLastCol As Long<br />
Dim iLastRow As Long<br />
Dim iLastRowList As Long<br />
Dim rngCTab As Range &#8216;Used for range in Sheet1 cross tab sheet<br />
Dim rngList As Range &#8216;Destination range for the list<br />
Dim ROW As Long</p>
<p>Set wsCrossTab = Worksheets(&#8220;Sheet1&#8243;) <span style="color: #008000;">&#8216;AMEND TO SHOW SHEET NUMBER WITH THE CROSS </span>TAB<br />
Set wsList = Worksheets.Add</p>
<p><span style="color: #008000;">&#8216;Find the last row in Sheet1 with the cross tab</span><br />
iLastRow = wsCrossTab.Cells(Rows.Count, &#8220;A&#8221;).End(xlUp).ROW</p>
<p><span style="color: #008000;">&#8216;Set the initial value for the row in the destination worksheet</span><br />
iLastRowList = 2</p>
<p><span style="color: #008000;">&#8216;Find the last column in Sheet1 with the cross tab<br />
</span>iLastCol = wsCrossTab.Range(&#8220;A2&#8243;).End(xlToRight).Column</p>
<p><span style="color: #008000;">&#8216;SET THE HEADING TITLES IN THE LIST SHEET<br />
</span>wsList.Range(&#8220;A1:F1&#8243;) = Array(&#8220;NAME&#8221;, &#8220;PROJECT&#8221;, &#8220;TYPE&#8221;, &#8220;PLAN/ACTUAL&#8221;, &#8220;WEEK&#8221;, &#8220;HOURS&#8221;)</p>
<p><span style="color: #008000;">&#8216;Start looping through the cross tab data</span></p>
<p>For ROW = 3 To iLastRow <span style="color: #008000;">&#8216;START AT ROW 3 AS THIS IS WHERE DATA BEGINS</span><br />
Set rngCTab = wsCrossTab.Range(&#8220;A&#8221; &amp; ROW, &#8220;C&#8221; &amp; ROW) <span style="color: #008000;">&#8216;initial value A3 SETS THE RANGE TO</span></p>
<p><span style="color: #008000;">&#8216;INCLUDE ALL STATIC DATA &#8211; IN THIS CASE NAME, PROJECT, TYPE<br />
</span>Set rngList = wsList.Range(&#8220;A&#8221; &amp; iLastRowList) &#8216;initial value A3</p>
<p><span style="color: #008000;">&#8216;Copy individual names in Col A (A3 initially) into as many rows as there are data columns</span><br />
<span style="color: #008000;">&#8216;in the cross tab (less 3 for Col A-C).</span><br />
rngCTab.Copy rngList.Resize(iLastCol &#8211; 3)</p>
<p><span style="color: #008000;">&#8216;SELECT THE HEADING ROW WITH FORECAST/ACTUAL<br />
&#8216;Move up ROW (INITIALLY 3) rows less TWO and across 3 columns (using offset function). Copy.<br />
</span>rngCTab.Offset(-(ROW &#8211; 2), 3).Resize(, iLastCol &#8211; 3).Copy</p>
<p><span style="color: #008000;">&#8216;Paste transpose to columns in the list sheet alongside the static data<br />
</span>rngList.Offset(0, 3).PasteSpecial Transpose:=True</p>
<p><span style="color: #008000;">&#8216;SELECT THE ROW WITH THE WEEK NUMBERS<br />
</span><span style="color: #008000;">&#8216;Move up ROW (INITIALLY 3) rows less ONE and across 3 columns (using offset function). Copy.<br />
</span>rngCTab.Offset(-(ROW &#8211; 1), 3).Resize(, iLastCol &#8211; 3).Copy</p>
<p><span style="color: #008000;">&#8216;Paste transpose to columns in the list sheet alongside the static data<br />
</span>rngList.Offset(0, 4).PasteSpecial Transpose:=True</p>
<p><span style="color: #008000;">&#8216;Staying on same row (3 initially) copy the data from the cross tab</span><br />
rngCTab.Offset(, 3).Resize(, iLastCol &#8211; 3).Copy</p>
<p><span style="color: #008000;">&#8216;Past transpose as column in list sheet</span><br />
rngList.Offset(0, 5).PasteSpecial Transpose:=True</p>
<p><span style="color: #008000;">&#8216;Set the new last row in list sheet to be just below the last name copied</span><br />
iLastRowList = iLastRowList + (iLastCol &#8211; 3)</p>
<p><span style="color: #008000;">&#8216;increment ROW by 1</span><br />
Next ROW</p>
<p><strong>End Sub</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2010/07/excel-pivot-table-or-crosstab-to-flat-list/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>VBA Snippets &#8211; Sorting Arrays and Random Selection</title>
		<link>http://whatapalaver.co.uk/2010/01/vba-snippets-sorting-arrays-and-random-selection/</link>
		<comments>http://whatapalaver.co.uk/2010/01/vba-snippets-sorting-arrays-and-random-selection/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 16:24:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://whatapalaver.co.uk/?p=1533</guid>
		<description><![CDATA[The blog post sounds a little Darwinian but I&#8217;m afraid it&#8217;s just a dull selection of VBA code that enables you to sort one array on the basis of values from another. A double sorting array. I&#8217;ve amended array sorting code from John Walkenbach and Anthony&#8217;s VBA Tutorials to create something I can understand. The [...]]]></description>
			<content:encoded><![CDATA[<p>The blog post sounds a little Darwinian but I&#8217;m afraid it&#8217;s just a dull selection of VBA code that enables you to sort one array on the basis of values from another. A double sorting array.</p>
<p>I&#8217;ve amended array sorting code from John Walkenbach and <a href="http://www.anthony-vba.kefra.com/vba/excelvba-simulation.htm#Creating_and_Managing_Array" rel="nofollow" >Anthony&#8217;s VBA Tutorials</a> to create something I can understand.</p>
<p>The DbleBubbleSort routine takes two arrays as arguments and sorts the string array (y) on the basis of the values in a nuber array (x). I&#8217;m using John Walkenbachs BubbleSort methodology which is simple but undoubtedly not the most efficient.</p>
<blockquote><p><strong>Sub DbleBubbleSort(x() As Single, y() As String)</strong></p>
<p><span style="color: #339966;">&#8216; adapting the BubbleSort method to sort an array on the basis of the values in another array.<br />
&#8216; x is an array of numbers (can be random as in the DbleSortTest() routine)<br />
&#8216; y is a string array</span><br />
    Dim First As Integer, Last As Long<br />
    Dim i As Long, j As Long<br />
    Dim xtemp As Single<br />
    Dim ytemp As String<br />
   <br />
    First = LBound(x)<br />
    Last = UBound(x)<br />
    For i = First To Last &#8211; 1<br />
        For j = i + 1 To Last<br />
            If x(i) &gt; x(j) Then<br />
                xtemp = x(j)<br />
                ytemp = y(j)<br />
                x(j) = x(i)<br />
                y(j) = y(i)<br />
                x(i) = xtemp<br />
                y(i) = ytemp<br />
            End If<br />
        Next j<br />
    Next i<br />
<strong>End Sub</strong></p></blockquote>
<p>The following routine calls on the DbleBubbleSort sub routine and uses it to provide a random selection of 3 entries from a string array.</p>
<blockquote><p><strong>Sub DbleSortTest()<br />
</strong><span style="color: #339966;">&#8216;this is an amended version of a function on </span><a href="http://www.anthony-vba.kefra.com/vba/excelvba-simulation.htm#Creating_and_Managing_Array" rel="nofollow" ><span style="color: #0000ff;">http://www.anthony-vba.kefra.com/vba/excelvba-simulation.htm#Creating_and_Managing_Array</span></a><br />
<span style="color: #339966;">&#8216;it randomly selects 3 entries from a text array (y)<br />
&#8216;it utilises a random number array and the sorting of one array based on the values in another.</span></p>
<p>    Dim i As Long<br />
    Dim x(8) As Single, y(8) As String<br />
    Dim str As String</p>
<p>    y(1) = &#8220;Anthony&#8221;<br />
    y(2) = &#8220;Bobby&#8221;<br />
    y(3) = &#8220;Chris&#8221;<br />
    y(4) = &#8220;Danny&#8221;<br />
    y(5) = &#8220;Eton&#8221;<br />
    y(6) = &#8220;Frank&#8221;<br />
    y(7) = &#8220;George&#8221;<br />
    y(8) = &#8220;Harry&#8221;<br />
   <br />
   <span style="color: #339966;"> &#8216;enters the x array into a worksheet<br />
</span>    For i = 1 To UBound(x)<br />
        x(i) = Rnd<br />
        Cells(i, 2) = x(i)<br />
    Next i<br />
   <br />
  <span style="color: #339966;">  &#8216;enters the y array in column 3 of the worksheet</span><br />
    For i = 1 To UBound(y)<br />
        Cells(i, 3) = y(i)<br />
    Next i<br />
   <br />
    Call DbleBubbleSort(x, y)<br />
   <br />
   <span style="color: #339966;"> &#8216;calls the first 3 values of y sorted according to x and enters them in the worksheet<br />
</span>    str = &#8220;&#8221;<br />
    For i = 1 To 3<br />
        str = str &amp; y(i) &amp; vbCrLf<br />
        Cells(i, 1) = y(i)<br />
    Next i</p>
<p>    MsgBox str<br />
<strong>End Sub</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2010/01/vba-snippets-sorting-arrays-and-random-selection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA Snippets to Sort Arrays in VBA</title>
		<link>http://whatapalaver.co.uk/2010/01/vba-snippets-to-sort-arrays-in-vba/</link>
		<comments>http://whatapalaver.co.uk/2010/01/vba-snippets-to-sort-arrays-in-vba/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 14:54:42 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[arrays]]></category>
		<category><![CDATA[sorting]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://whatapalaver.co.uk/?p=1526</guid>
		<description><![CDATA[Here&#8217;s another VBA snippet post. I find it handy to have a store of regularly used macros on the blog so I can access them at any time, not that I need them that often of course. These particular snippets are useful routines for sorting arrays and can be called from other procedures. I&#8217;ve taken [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s another VBA snippet post. I find it handy to have a store of regularly used macros on the blog so I can access them at any time, not that I need them that often of course.</p>
<p>These particular snippets are useful routines for sorting arrays and can be called from other procedures. I&#8217;ve taken these particular ones from John Walkenbach&#8217;s book: Excel 2007 Power Programming with VBA. I&#8217;m working my way through <a href="http://www.anthony-vba.kefra.com/" rel="nofollow" >Anthony&#8217;s VBA tutorials</a> for excel modelling and array sorting is regular feature.</p>
<p>The BubbleSort code is easy to understand and therefore one of my favourites but the other 3 methods are much quicker for arrays with more than 500 entries.</p>
<blockquote><p><strong>Sub BubbleSort(list() As String)</strong><br />
<span style="color: #339966;">&#8216; Taken from power programming with VBA<br />
&#8216; It&#8217;s a sorting procedure for 1-dimensional arrays named List<br />
&#8216; The procedure takes each array element, if it is greater than the next element, the two elements swap positions.<br />
&#8216; The evaluation is repeated for every pair of items (that is n-1 times)<br />
&#8216; Change data type to As Integer if your array isn&#8217;t text</span><br />
    Dim First As Integer, Last As Long<br />
    Dim i As Long, j As Long<br />
    Dim temp As String<br />
    First = LBound(list)<br />
    Last = UBound(list)<br />
    For i = First To Last &#8211; 1<br />
        For j = i + 1 To Last<br />
            If list(i) &gt; list(j) Then<br />
                temp = list(j)<br />
                list(j) = list(i)<br />
                list(i) = temp<br />
            End If<br />
        Next j<br />
    Next i<br />
<strong>End Sub</strong></p></blockquote>
<p>You can test this macro with the following routine which pastes the results into the immediate window.</p>
<blockquote><p><strong>Sub SortTester()<br />
</strong>   <br />
    Dim x(1 To 5) As String<br />
    Dim i As Long<br />
   <br />
    x(1) = &#8220;egg&#8221;<br />
    x(2) = &#8220;apple&#8221;<br />
    x(3) = &#8220;stuff&#8221;<br />
    x(4) = &#8220;nonsense&#8221;<br />
    x(5) = &#8220;1&#8243;<br />
   <br />
    Call BubbleSort(x)<br />
   <br />
    For i = 1 To 5<br />
        Debug.Print i, x(i)<br />
    Next i<br />
<strong>End Sub</strong></p></blockquote>
<p>Here are a few more sort options which are a bit more efficient but unfortunately more complex.</p>
<blockquote><p><strong>Sub WorksheetSort(list)<br />
</strong><span style="color: #339966;">&#8216;   Sorts an array by transferring it to<br />
&#8216;   A worksheet and using Excel&#8217;s sorting command<br />
</span>   <br />
    Dim First As Integer, Last As Long<br />
    Dim i As Long<br />
    Dim FirstCell As Range, LastCell As Range<br />
    Dim CurrCell As Range, FillRange As Range<br />
   <br />
    First = LBound(list, 1)<br />
    Last = UBound(list, 1)<br />
    Set FirstCell = Sheets(&#8220;Sheet1&#8243;).Cells(1, 1)<br />
    Set LastCell = Sheets(&#8220;Sheet1&#8243;).Cells(Last, 1)<br />
    Set FillRange = Range(FirstCell, LastCell)<br />
    Application.ScreenUpdating = False<br />
   <br />
<span style="color: #339966;">&#8216;   Transfer the array to worksheet<br />
</span>    FillRange.Value = list<br />
   <br />
<span style="color: #339966;">&#8216;   Sort the worksheet range<br />
</span>    FirstCell.CurrentRegion.Sort Key1:=FirstCell, Order1:=xlAscending, Orientation:=xlTopToBottom<br />
      <br />
<span style="color: #339966;">&#8216;   Transfer range back to the array and clear range<br />
</span>    For i = First To Last<br />
        list(i, 0) = FirstCell.Offset(i &#8211; 1, 0)<br />
    Next i<br />
    FillRange.Clear<br />
    Application.ScreenUpdating = True<br />
<strong>End Sub</strong></p>
<p><strong>Public Sub Quicksort(list() As Long, ByVal min As Long, ByVal max As Long)  </strong><br />
<span style="color: #339966;">&#8216;This technique works only with Integer or Long values.</span><br />
Dim med_value As Long<br />
    Dim hi As Long<br />
    Dim lo As Long<br />
    Dim i As Long</p>
<p>   <span style="color: #339966;"> &#8216; If min &gt;= max, the list contains 0 or 1 items so it<br />
    &#8216; is sorted.<br />
</span>    If min &gt;= max Then Exit Sub</p>
<p>  <span style="color: #339966;">  &#8216; Pick the dividing value.<br />
</span>    i = Int((max &#8211; min + 1) * Rnd + min)<br />
    med_value = list(i)</p>
<p> <span style="color: #339966;">   &#8216; Swap it to the front.<br />
</span>    list(i) = list(min)</p>
<p>    lo = min<br />
    hi = max<br />
    Do<br />
      <span style="color: #339966;">  &#8216; Look down from hi for a value &lt; med_value.<br />
</span>        Do While list(hi) &gt;= med_value<br />
            hi = hi &#8211; 1<br />
            If hi &lt;= lo Then Exit Do<br />
        Loop<br />
        If hi &lt;= lo Then<br />
            list(lo) = med_value<br />
            Exit Do<br />
        End If</p>
<p>       <span style="color: #339966;"> &#8216; Swap the lo and hi values.<br />
</span>        list(lo) = list(hi)<br />
       <br />
       <span style="color: #339966;"> &#8216; Look up from lo for a value &gt;= med_value.<br />
</span>        lo = lo + 1<br />
        Do While list(lo) &lt; med_value<br />
            lo = lo + 1<br />
            If lo &gt;= hi Then Exit Do<br />
        Loop<br />
        If lo &gt;= hi Then<br />
            lo = hi<br />
            list(hi) = med_value<br />
            Exit Do<br />
        End If<br />
       <br />
       <span style="color: #339966;"> &#8216; Swap the lo and hi values.<br />
</span>        list(hi) = list(lo)<br />
    Loop<br />
   <br />
    <span style="color: #339966;">&#8216; Sort the two sublists.<br />
</span>    Quicksort list(), min, lo &#8211; 1<br />
    Quicksort list(), lo + 1, max<br />
<strong>End Sub</strong></p>
<p><strong>Sub Countingsort(list)</strong><br />
<span style="color: #339966;">&#8216;This technique works only with Integer or Long values.</span><br />
Dim counts()<br />
    Dim i As Long<br />
    Dim j As Long<br />
    Dim next_index As Long<br />
    Dim min, max<br />
    Dim min_value As Variant, max_value As Variant</p>
<p><span style="color: #339966;">&#8216;   Allocate the counts array. VBA automatically<br />
&#8216;   initialises all entries to 0.</span></p>
<p>    min_value = Minimum(list)<br />
    max_value = Maximum(list)</p>
<p>    min = LBound(list)<br />
    max = UBound(list)<br />
   <br />
    ReDim counts(min_value To max_value)<br />
   <br />
<span style="color: #339966;">    &#8216; Count the values.<br />
</span>    For i = min To max<br />
        counts(list(i)) = counts(list(i)) + 1<br />
    Next i</p>
<p>   <span style="color: #339966;"> &#8216; Write the items back into the list array.<br />
</span>    next_index = min<br />
    For i = min_value To max_value<br />
        For j = 1 To counts(i)<br />
            list(next_index) = i<br />
            next_index = next_index + 1<br />
        Next j<br />
    Next i<br />
<strong>End Sub</strong></p>
<p><strong>Function Minimum(list)<br />
</strong>    Dim i As Long<br />
    Minimum = list(LBound(list))<br />
    For i = LBound(list) To UBound(list)<br />
        If list(i) &lt; Minimum Then Minimum = list(i)<br />
    Next i<br />
<strong>End Function</strong></p>
<p><strong>Function Maximum(list)<br />
</strong>    Dim i As Long<br />
    Maximum = list(LBound(list))<br />
    For i = LBound(list) To UBound(list)<br />
        If list(i) &gt; Maximum Then Maximum = list(i)<br />
    Next i<br />
<strong>End Function</strong></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2010/01/vba-snippets-to-sort-arrays-in-vba/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>VBA Snippets to Delete Rows in Excel</title>
		<link>http://whatapalaver.co.uk/2009/09/vba-snippets-to-delete-rows-in-excel/</link>
		<comments>http://whatapalaver.co.uk/2009/09/vba-snippets-to-delete-rows-in-excel/#comments</comments>
		<pubDate>Sat, 05 Sep 2009 15:21:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[delete rows]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://whatapalaver.co.uk/?p=1059</guid>
		<description><![CDATA[I regularly use simple macros to delete blank rows in my excel spreadsheets and there are loads of examples on internet forums. I&#8217;ve recently had to recreate these delete row macros to install on a new computer and thought it would be useful to keep them filed here on the blog. This first macro will [...]]]></description>
			<content:encoded><![CDATA[<p>I regularly use simple macros to delete blank rows in my excel spreadsheets and there are loads of examples on internet forums.</p>
<p style="float: right; margin-left: 10px; margin-bottom: 10px"><img class="alignright size-full wp-image-1062" title="Screen shot 2009-09-05 at 15.59.57" src="http://whatapalaver.co.uk/wp-content/uploads/2009/09/Screen-shot-2009-09-05-at-15.59.57.png" alt="Screen shot 2009-09-05 at 15.59.57" width="236" height="173" /></p>
<p>I&#8217;ve recently had to recreate these delete row macros to install on a new computer and thought it would be useful to keep them filed here on the blog.</p>
<p>This first macro will delete any row in which the cell in the selected column is blank. So in this example, with column B selected, rows 4 &amp; 7 will be deleted.</p>
<blockquote><p><strong>Sub DeleteRowOnBlankCell()</strong></p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216;Deletes entire row within the selected column where cell within selection is blank</span></p>
<p style="padding-left: 30px;"><span style="color: #008000;"> ‘Select column then run the macro</span></p>
<p style="padding-left: 60px;">On Error Resume Next</p>
<p style="padding-left: 90px;">Selection.EntireRow.SpecialCells(xlBlanks).EntireRow.Delete</p>
<p style="padding-left: 60px;">On Error GoTo 0</p>
<p style="padding-left: 60px;">
<p style="padding-left: 60px;">
<p><strong>End Sub</strong></p></blockquote>
<p>The following macro will only delete rows if the entire row is blank. Just select the area you want to evaluate and run the macro.</p>
<blockquote><p><strong>Sub DeleteBlankRows()</strong></p></blockquote>
<blockquote>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216;Deletes the entire row within the selection provided the ENTIRE row is blank.</span></p>
<p style="padding-left: 30px;"><span style="color: #008000;">Dim i As Long</span></p>
<p style="padding-left: 60px;">For i = Selection.Rows.Count To 1 Step -1</p>
<p style="padding-left: 90px;">If WorksheetFunction.CountA(Selection.Rows(i)) = 0 Then</p>
<p style="padding-left: 120px;">Selection.Rows(i).EntireRow.Delete</p>
<p style="padding-left: 90px;">End If</p>
<p style="padding-left: 60px;">Next i</p>
<p style="padding-left: 60px;">
<p style="padding-left: 60px;">
</blockquote>
<blockquote><p><strong>End Sub</strong></p></blockquote>
<p>To use these macros just copy and paste them into a module within your personal macro workbook (press ALT F11 to open the VBA editor) which will make them available for use whenever excel is open. Sometimes the personal workbook doesn&#8217;t show up in the VBA editor and if this is the case I just record a new macro, select the option to save it in the personal workbook, make a few changes to a spreadsheet and stop recording. This will have the effect of creating a new module in  personal.xls, along with a fairly useless macro that can now be deleted.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/09/vba-snippets-to-delete-rows-in-excel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Conditional Ranking in Excel &#8211; RankIF using SumProduct</title>
		<link>http://whatapalaver.co.uk/2009/09/conditional-ranking-in-excel-rankif-using-sumproduct/</link>
		<comments>http://whatapalaver.co.uk/2009/09/conditional-ranking-in-excel-rankif-using-sumproduct/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 10:16:02 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[RANKIF]]></category>
		<category><![CDATA[Sumproduct]]></category>

		<guid isPermaLink="false">http://whatapalaver.co.uk/?p=1053</guid>
		<description><![CDATA[I was hunting around for a RANKIF function yesterday so I could rank a load of hospitals in terms of their cost per procedure. Unfortunately RANKIF isn’t one of the available functions but I managed to achieve the same effect by utilising the SUMPRODUCT function. I wrote a SUMPRODUCT tutorial some time ago indicating how [...]]]></description>
			<content:encoded><![CDATA[<p>I was hunting around for a RANKIF function yesterday so I could rank a load of hospitals in terms of their cost per procedure.</p>
<p><img class="aligncenter size-full wp-image-1054" title="RankIF" src="http://whatapalaver.co.uk/wp-content/uploads/2009/09/RankIF.jpg" alt="RankIF" width="422" height="305" /></p>
<p>Unfortunately RANKIF isn’t one of the available functions but I managed to achieve the same effect by utilising the SUMPRODUCT function.</p>
<p>I wrote a <a href="http://whatapalaver.co.uk/2007/09/sumproduct/">SUMPRODUCT tutorial</a> some time ago indicating how the powerful function can act as a multi conditioned SUMIF formula but it seems it can also act as a multi conditioned RANKIF formula as well.</p>
<p>The formula I used to achieve the above ranking was:</p>
<p>=1+SUMPRODUCT(($B$2:$B$12=B2)*($C$2:$C$12&gt;C2))</p>
<p>Copied down the column it will return the number of organisations for a given procedure which have costs higher than the selected row. Adding 1 to the result just ensures that the highest cost organisation starts with a rank of 1 rather than 0.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/09/conditional-ranking-in-excel-rankif-using-sumproduct/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Excel CrossTab Table to Flat List</title>
		<link>http://whatapalaver.co.uk/2009/07/excel-crosstab-table-to-flat-list/</link>
		<comments>http://whatapalaver.co.uk/2009/07/excel-crosstab-table-to-flat-list/#comments</comments>
		<pubDate>Wed, 29 Jul 2009 12:23:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[Pivot Table]]></category>
		<category><![CDATA[table]]></category>
		<category><![CDATA[used range]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.angelawolff.co.uk/Excel/stream/archives/62</guid>
		<description><![CDATA[I had a query on my sumproduct tutorial that was effectively asking if I could work backwards from an excel crosstab or data table to get back to the simple flat list. Converting a table like this: Back to the data sheet like this: If you didn’t have to do this sort of task very [...]]]></description>
			<content:encoded><![CDATA[<p>I had a query on my <a href="http://www.angelawolff.co.uk/Excel/stream/2007/09/27/sumproduct/" rel="nofollow" >sumproduct tutorial</a> that was effectively asking if I could work backwards from an excel crosstab or data table to get back to the simple flat list.</p>
<p>Converting a table like this:</p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2007/09/sumproduct31.gif"title="sumproduct" ><img src="http://whatapalaver.co.uk/wp-content/uploads/2007/09/sumproduct31.gif" alt="sumproduct" /></a></p>
<p>Back to the data sheet like this:</p>
<p><a href="http://whatapalaver.co.uk/wp-content/uploads/2007/09/sumproduct11.gif"title="sumproduct" ><img src="http://whatapalaver.co.uk/wp-content/uploads/2007/09/sumproduct11.gif" alt="sumproduct" /></a></p>
<p>If you didn’t have to do this sort of task very often you could get by with a pivot table solution and a few stages of formatting but it would only work if your data values were numbers that could be summed in the pivot.</p>
<p>If you need to convert Excel data tables (or crosstabs) into flat lists on a regular basis then you will need a macro.</p>
<p>I have prepared a workbook that demonstrates both the pivot table and macro solution and you can download it from here:<br />
<a href="http://whatapalaver.co.uk/wp-content/uploads/2009/07/crosstab-to-list-macro1.xls"title="Excel Table to Flat List" >ExcelTabletoFlatList.xls</a></p>
<p>The following macro does the trick and utilises the VBA I introduced in my <a href="http://www.angelawolff.co.uk/Excel/stream/2009/07/24/macros-to-consolidate-worksheets/" rel="nofollow" >last post on consolidating worksheets,</a> to determine the last used row and last used column.</p>
<p>Sub CrossTabToList()</p>
<p>Dim wsCrossTab As Worksheet<br />
Dim wsList As Worksheet<br />
Dim iLastCol As Long<br />
Dim iLastRow As Long<br />
Dim iLastRowList As Long<br />
Dim rngCTab As Range <span style="color: green;">&#8216;Used for range in Sheet1 cross tab sheet</span><br />
Dim rngList As Range <span style="color: green;">&#8216;Destination range for the list</span><br />
Dim I As Long</p>
<p>Set wsCrossTab = Worksheets(&#8220;Sheet1&#8243;)<br />
Set wsList = Worksheets.Add</p>
<p><span style="color: green;">&#8216;Find the last row in Sheet1 with the cross tab</span><br />
iLastRow = wsCrossTab.Cells(Rows.Count, &#8220;A&#8221;).End(xlUp).Row</p>
<p><span style="color: green;">&#8216;Set the initial value for the row in the destination worksheet</span><br />
iLastRowList = 2</p>
<p><span style="color: green;">&#8216;Find the last column in Sheet1 with the cross tab</span><br />
iLastCol = wsCrossTab.Range(&#8220;A1&#8243;).End(xlToRight).Column</p>
<p><span style="color: green;">&#8216;Create a new sheet and set the heading titles</span><br />
wsList.Range(&#8220;A1:C1&#8243;) = Array(&#8220;NAME&#8221;, &#8220;GRADE&#8221;, &#8220;VALUE&#8221;)</p>
<p><span style="color: green;">&#8216;Start looping through the cross tab data</span></p>
<p>For I = 2 To iLastRow</p>
<p>Set rngCTab = wsCrossTab.Range(&#8220;A&#8221; &amp; I) <span style="color: green;">&#8216;initial value A2</span><br />
Set rngList = wsList.Range(&#8220;A&#8221; &amp; iLastRowList) <span style="color: green;">&#8216;initial value A2</span></p>
<p><span style="color: green;">&#8216;Copy individual names in Col A (A2 initially) into as many rows as there are data columns</span><br />
<span style="color: green;">&#8216;in the cross tab (less 1 for Col A). </span><br />
rngCTab.Copy rngList.Resize(iLastCol &#8211; 1)</p>
<p><span style="color: green;">&#8216;Move up a I rows less one and across one column (using offset function) to select heading row. Copy. </span><br />
rngCTab.Offset(-(I &#8211; 1), 1).Resize(, iLastCol &#8211; 1).Copy</p>
<p><span style="color: green;">&#8216;Paste transpose to columns in the list sheet alongside the names</span><br />
rngList.Offset(0, 1).PasteSpecial Transpose:=True</p>
<p><span style="color: green;">&#8216;Staying on same row (2 initially) copy the data from the cross tab</span><br />
rngCTab.Offset(, 1).Resize(, iLastCol &#8211; 1).Copy</p>
<p><span style="color: green;">&#8216;Past transpose as column in list sheet</span><br />
rngList.Offset(0, 2).PasteSpecial Transpose:=True</p>
<p><span style="color: green;">&#8216;Set the new last row in list sheet to be just below the last name copied</span><br />
iLastRowList = iLastRowList + (iLastCol &#8211; 1)</p>
<p><span style="color: green;">&#8216;increment I by 1</span><br />
Next I</p>
<p>End Sub</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/07/excel-crosstab-table-to-flat-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Macros to Consolidate Worksheets</title>
		<link>http://whatapalaver.co.uk/2009/07/macros-to-consolidate-worksheets/</link>
		<comments>http://whatapalaver.co.uk/2009/07/macros-to-consolidate-worksheets/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 15:36:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[consolidate worksheets]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[select macro]]></category>
		<category><![CDATA[used range]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.angelawolff.co.uk/Excel/stream/archives/61</guid>
		<description><![CDATA[I’ve got a spreadsheet with tabs for each individual directorate. Within the tabs are tables with the same layout but different sizes (number of rows). I want to group together all the used data on each tab and create a single consolidated sheet of continuous data. Obviously I need a macro to copy and paste [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve got a spreadsheet with tabs for each individual directorate. Within the tabs are tables with the same layout but different sizes (number of rows).</p>
<p>I want to group together all the used data on each tab and create a single consolidated sheet of continuous data.</p>
<p>Obviously I need a macro to copy and paste my data from each sheet but the tricky bit is selecting the relevant (or used) area in each sheet.</p>
<p>On my search around the interweb I found some really useful snippets of VBA code on the <a href="http://www.ozgrid.com/" rel="nofollow" >Ozgrid website</a> which enable you to determine the last used row according to a number of different criteria and assign this to a variable such as “iLastRow”.</p>
<blockquote><p><span style="color: #008000;">&#8216;find row before next blank cell in column A</span><br />
iLastRow = Range(&#8220;A1&#8243;).End(xlDown).Row</p></blockquote>
<blockquote><p><span style="color: #008000;">&#8216;find last used row in column A</span><br />
iLastRow = Cells(Rows.Count, &#8220;a&#8221;).End(xlUp).Row</p></blockquote>
<blockquote><p><span style="color: #008000;">&#8216;find last used row on sheet</span><br />
iLastRow = Cells.Find(what:=&#8221;*&#8221;, SearchOrder:=xlByRows, _SearchDirection:=xlPrevious).Row</p></blockquote>
<p>It’s a simple step then to use this variable to define a range of used cells.</p>
<blockquote><p>Range(&#8220;A1:P&#8221; &amp; iLastRow).Select</p></blockquote>
<p>I’ve used the above techniques to consolidate my worksheets and here’s a copy of my working code:</p>
<blockquote><p><strong>Sub ConsolidateSheetsforSubForm()</strong></p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; ConsolidateSheetsforSubForm Macro</span></p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; Copies used subform data in individual sheets and pastes into one sheet as continuous data</span></p>
<p style="padding-left: 60px;">Sheets(&#8220;Ap Table Sub Form&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216;find last used row column a of Ap Table Sub Form sheet</span></p>
<p style="padding-left: 60px;">ilastrowsubf = Cells(Rows.Count, &#8220;a&#8221;).End(xlUp).Row</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; Clear the existing data in the subform sheet</span></p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216;specify location in subform to clear data</span></p>
<p style="padding-left: 60px;">Range(&#8220;a5:k&#8221; &amp; ilastrowsubf).ClearContents</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; Start selecting the data from Sheet S&amp;M (LY)</span></p>
<p style="padding-left: 60px;">Sheets(&#8220;S&amp;M (LY)&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; find last used row in column I</span></p>
<p style="padding-left: 60px;">ilastrowsm = Cells(Rows.Count, &#8220;i&#8221;).End(xlUp).Row</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; use ilastrowsm variable to define range to copy in S&amp;M sheet</span></p>
<p style="padding-left: 60px;">Range(&#8220;i4:s&#8221; &amp; ilastrowsm).Copy</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; specify location in subform to paste data</span></p>
<p style="padding-left: 60px;">Sheets(&#8220;Ap Table Sub Form&#8221;).Select</p>
<p style="padding-left: 60px;">Range(&#8220;a5&#8243;).Select</p>
<p style="padding-left: 60px;">Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _</p>
<p style="padding-left: 60px;">:=False, Transpose:=False</p>
<p style="padding-left: 60px;">Sheets(&#8220;K&amp;R (BV)&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; find last used row in column I of K&amp;R sheet</span></p>
<p style="padding-left: 60px;">ilastrowkr = Cells(Rows.Count, &#8220;i&#8221;).End(xlUp).Row</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; use ilastrowkr variable to define range to copy in K&amp;R sheet</span></p>
<p style="padding-left: 60px;">Range(&#8220;i4:s&#8221; &amp; ilastrowkr).Copy</p>
<p style="padding-left: 60px;">Sheets(&#8220;Ap Table Sub Form&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; find first blank row in column a of Ap Table Sub Form sheet</span></p>
<p style="padding-left: 60px;">ifirstblankrowsubf = (Cells(Rows.Count, &#8220;a&#8221;).End(xlUp).Row) + 1</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; specify location in subform to paste data</span></p>
<p style="padding-left: 60px;">Range(&#8220;a&#8221; &amp; ifirstblankrowsubf).Select</p>
<p style="padding-left: 60px;">Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _</p>
<p style="padding-left: 60px;">:=False, Transpose:=False</p>
<p style="padding-left: 60px;">Sheets(&#8220;OVERHEADS&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; find last used row in column I of OVERHEADS sheet</span></p>
<p style="padding-left: 60px;">ilastrowover = Cells(Rows.Count, &#8220;i&#8221;).End(xlUp).Row</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; use ilastrowover variable to define range to copy in OVERHEADS sheet</span></p>
<p style="padding-left: 60px;">Range(&#8220;i4:s&#8221; &amp; ilastrowover).Copy</p>
<p style="padding-left: 60px;">Sheets(&#8220;Ap Table Sub Form&#8221;).Select</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; find first blank row in column a of Ap Table Sub Form sheet</span></p>
<p style="padding-left: 60px;">ifirstblankrowsubf = (Cells(Rows.Count, &#8220;a&#8221;).End(xlUp).Row) + 1</p>
<p style="padding-left: 30px;"><span style="color: #008000;">&#8216; specify location in subform to paste data</span></p>
<p style="padding-left: 60px;">Range(&#8220;a&#8221; &amp; ifirstblankrowsubf).Select</p>
<p style="padding-left: 60px;">Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _</p>
<p style="padding-left: 60px;">:=False, Transpose:=False</p>
<p style="padding-left: 60px;">Range(&#8220;A5&#8243;).Select</p>
<p><strong>End Sub</strong></p></blockquote>
<p>You can do similar things in order to find the last column as well:</p>
<blockquote><p><span style="color: #008000;">&#8216;find column before next blank cell in row 1</span></p>
<p style="padding-left: 30px;">iLastColumn = Range(&#8220;A1&#8243;).End(xlToRight).Column</p>
<p><span style="color: #008000;">&#8216;find last used column in row 1</span></p>
<p style="padding-left: 30px;">iLastColumn = Cells(Columns.Count, &#8220;a&#8221;).End(xlToLeft).Column</p>
<p><span style="color: #008000;">&#8216;find last used column on sheet</span></p>
<p style="padding-left: 30px;">iLastColumn = Cells.Find(what:=&#8221;*&#8221;, SearchOrder:=xlByColumns, _</p>
<p style="padding-left: 30px;">SearchDirection:=xlPrevious).Column</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/07/macros-to-consolidate-worksheets/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vlookup Errors &#8211; The Third Way</title>
		<link>http://whatapalaver.co.uk/2009/04/vlookup-errors-the-third-way/</link>
		<comments>http://whatapalaver.co.uk/2009/04/vlookup-errors-the-third-way/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 20:19:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[#DIV/0!]]></category>
		<category><![CDATA[#N/A]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[Functions]]></category>
		<category><![CDATA[vlookup]]></category>

		<guid isPermaLink="false">http://www.angelawolff.co.uk/Excel/stream/archives/60</guid>
		<description><![CDATA[I&#8217;ve just published a post detailing a method of removing the errors returned by vlookup or hlookup utilising conditional formatting. I had previously been using the double vlookup method to replace errors with blanks or zeros but then discovered that these excessive lookup functions had a tendency to bloat my spreadsheets. While the conditional format [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just published a post detailing a method of <a href="http://www.angelawolff.co.uk/Excel/stream/2009/04/20/spreadsheet-efficiency-vlookup-and-conditional-formatting-to-remove-errors/" rel="nofollow" >removing the errors returned by vlookup or hlookup</a> utilising conditional formatting.</p>
<p>I had previously been using the double vlookup method to replace errors with blanks or zeros but then discovered that these excessive lookup functions had a tendency to bloat my spreadsheets.</p>
<p>While the conditional format method works, I can&#8217;t say that I particularly like it so I&#8217;ve been on the hunt for another method.</p>
<p>My first double lookup error hiding method looked like this:</p>
<p>=IF(ISERROR(VLOOKUP(L$7&#038;$C13,’[WTE Apportionment Tables.xls]WTE APP TABLES SUB F’!$B:$K,9,0)),”&#8221;,VLOOKUP(L$7&#038;$C13,’[WTE Apportionment Tables.xls]WTE APP TABLES SUB F’!$B:$K,9,0))</p>
<p>and here&#8217;s method no 3 that feels somewhat neater:</p>
<p>=IF([WTE Apportionment Tables.xls]WTE APP TABLES SUB F’!$B:$K,L$7&#038;$C13),VLOOKUP(L$7&#038;$C13,’[WTE Apportionment Tables.xls]WTE APP TABLES SUB F’!$B:$K,9,0))</p>
<p>That&#8217;s a working formula but it is a bit confusing, so here&#8217;s a simpler example the syntax:</p>
<p> =IF(COUNTIF(A1:A10,&#8221;Some Value&#8221;),VLOOKUP(&#8220;Some Value&#8221;,A1:B10,2,FALSE),0)</p>
<p>The COUNTIF function is a logical function and will return TRUE or FALSE depending on whether &#8220;Some Value&#8221; is found in the range A1:A10. The IF function follows the format =IF(logical test, value if true, value if false). So if the COUNTIF function is TRUE the VLOOKUP will run, if it is FALSE the value 0 is returned.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/04/vlookup-errors-the-third-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spreadsheet Efficiency: VLookup and Conditional Formatting to Remove Errors</title>
		<link>http://whatapalaver.co.uk/2009/04/spreadsheet-efficiency-vlookup-and-conditional-formatting-to-remove-errors/</link>
		<comments>http://whatapalaver.co.uk/2009/04/spreadsheet-efficiency-vlookup-and-conditional-formatting-to-remove-errors/#comments</comments>
		<pubDate>Mon, 20 Apr 2009 19:59:23 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[#DIV/0!]]></category>
		<category><![CDATA[#N/A]]></category>
		<category><![CDATA[conditional formatting]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[Formatting]]></category>
		<category><![CDATA[vlookup]]></category>

		<guid isPermaLink="false">http://www.angelawolff.co.uk/Excel/stream/archives/59</guid>
		<description><![CDATA[I’ve started working at a new hospital and it seems to be plagued by unwieldy spreadsheets that have a tendency to crawl through saves and then sometimes refuse to open. They are riddled with links and lookups to external spreadsheets and the whole thing feels fairly precarious. I’ve been reading a bit about good spreadsheet [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve started working at a new hospital and it seems to be plagued by unwieldy spreadsheets that have a tendency to crawl through saves and then sometimes refuse to open. They are riddled with links and lookups to external spreadsheets and the whole thing feels fairly precarious.</p>
<p>I’ve been reading a bit about <a href="http://www.ozgrid.com/Excel/ExcelSpreadsheetDesign.htm" rel="nofollow" >good spreadsheet design</a> with a view to whittling down the complexity and discovered that lookup functions are particularly demanding on the system.</p>
<p>Now I’m quite a sinner when it comes to the use of the double lookup function to remove errors such as #N/A and #DIV/0!</p>
<p>Here’s an example of such a formula that returns a blank if the first lookup function results in an error:</p>
<p>=IF(ISERROR(VLOOKUP(L$7&amp;$C13,&#8217;[WTE Apportionment Tables.xls]WTE APP TABLES SUB F&#8217;!$B:$K,9,0)),&#8221;",VLOOKUP(L$7&amp;$C13,&#8217;[WTE Apportionment Tables.xls]WTE APP TABLES SUB F&#8217;!$B:$K,9,0))</p>
<p>It works fine, but it doubles up the number of lookups that Excel needs to run through and for a large spreadsheet this can really slow down the performance.</p>
<p>It seems that conditional formatting is a suitable alternative but one that I’ve always ignored because I didn’t know how to structure the condition to work for errors.</p>
<p>I do now though and here’s how:</p>
<p style="float: right; margin-left: 10px; margin-bottom: 10px"><a href="http://www.flickr.com/photos/warriorwomen/3460389684/" rel="nofollow" class="tt-flickr" ><img src="http://whatapalaver.co.uk/wp-content/uploads/2009/04/excel-300x208.jpg" alt="excel" title="excel" width="300" height="208" /></a></p>
<p>1. Select the range you wish to apply the format to.<br />
2. Goto Format &#8211; Conditional Formatting<br />
3. Select Formula Is in the drop down box<br />
4. Type the formula =iserror(ref) where ref is the reference to the first cell selected in the range<br />
5. Hit Format and select the font colour to be white<br />
6. OK &#8211; finished the job</p>
<p style="float: right; margin-left: 10px; margin-bottom: 10px"><a href="http://www.flickr.com/photos/warriorwomen/3460390026/" rel="nofollow" class="tt-flickr" ><img src="http://farm4.static.flickr.com/3580/3460390026_e60f04c286_m.jpg" border="0" alt="Conditional Format 2" width="144" height="240" /></a></p>
<p>My current spreadsheet hasn’t grown that large yet but nevertheless it had 7200 of the double vlookups in 18 columns, by removing the unnecessary error catching lookup I dropped the file size by 22%.</p>
<p>As the errors weren&#8217;t actually removed, I had to use an array formula to get the totals for the column but that was included in the space saving above.</p>
<p>The array formula for summing a range with error values:</p>
<p>{=SUM(IF(ISNUMBER(H12:H418),(H12:H418)))}</p>
<p>NB. The curly brackets are achieved by entering the formula using CONTROL, SHIFT, ENTER.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2009/04/spreadsheet-efficiency-vlookup-and-conditional-formatting-to-remove-errors/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding an Image to the Header or Footer of Every Sheet</title>
		<link>http://whatapalaver.co.uk/2008/01/adding-image-in-to-the-header-of-every-sheet/</link>
		<comments>http://whatapalaver.co.uk/2008/01/adding-image-in-to-the-header-of-every-sheet/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 01:08:47 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Excel]]></category>
		<category><![CDATA[Geeky Corner]]></category>
		<category><![CDATA[excel]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[Macros]]></category>
		<category><![CDATA[VBA]]></category>

		<guid isPermaLink="false">http://www.angelawolff.co.uk/Excel/stream/archives/56</guid>
		<description><![CDATA[From Excel 2002 onwards you can enter an image, probably a logo, into the header or footer of your worksheet. This code enables you to create a macro that will automate the addition of the logo to every sheet in your workbook. Sub MultipleHeader() &#8216;created 10/01/2008 by Angela Wolff Application.ScreenUpdating = False &#8216; stops the [...]]]></description>
			<content:encoded><![CDATA[<p>From Excel 2002 onwards you can enter an image, probably a logo, into the header or footer of your worksheet. This code enables you to create a macro that will automate the addition of the logo to every sheet in your workbook.</p>
<blockquote><p>Sub MultipleHeader()<br />
<font color="green">&#8216;created 10/01/2008 by Angela Wolff</font><br />
Application.ScreenUpdating = False <font color="green">&#8216; stops the flashing</font><br />
   Dim WS_Count As Integer<br />
   Dim I As Integer<br />
   <font color="green">&#8216; Set WS_Count equal to the number of worksheets in the active workbook.</font><br />
   WS_Count = ActiveWorkbook.Worksheets.Count<br />
   <font color="green">&#8216; Begin loop.</font><br />
   For I = 1 To WS_Count<br />
      ActiveWorkbook.Worksheets(I).Activate<br />
      ActiveSheet.PageSetup.RightHeaderPicture.Filename = _<br />
        &#8220;C:\Document\hhnt_007528.jpg&#8221; <font color="green">&#8216;obviously change this to the image and path of your desire.</font><br />
    ActiveSheet.PageSetup.PrintArea = &#8220;&#8221;<br />
    With ActiveSheet.PageSetup<br />
        .RightHeader = &#8220;&#038;G&#8221;<br />
    End With<br />
   Next I<br />
End Sub</p></blockquote>
<p>NB. The <font colour="blue">With End With</font> code is only really required if you are going to change a number of parameters at once.</p>
]]></content:encoded>
			<wfw:commentRss>http://whatapalaver.co.uk/2008/01/adding-image-in-to-the-header-of-every-sheet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 0.395 seconds -->
<!-- Cached page served by WP-Cache -->
