<?xml version="1.0" encoding="UTF-8" standalone="no"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:gd="http://schemas.google.com/g/2005" xmlns:georss="http://www.georss.org/georss" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:openSearch="http://a9.com/-/spec/opensearchrss/1.0/" xmlns:thr="http://purl.org/syndication/thread/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-882500965543473084</atom:id><lastBuildDate>Sun, 01 Oct 2023 06:10:02 +0000</lastBuildDate><category>Excel</category><category>Vba</category><category>Excel Formula</category><category>C#</category><category>Excel 2007</category><category>Pandas</category><category>Python</category><category>Excel 2010</category><category>Ms Access</category><category>Arrays</category><category>Java</category><category>Php</category><category>Csv</category><category>If Statement</category><category>Textjoin</category><category>Vb.net</category><category>Ado</category><category>Adodb</category><category>Advanced Filter</category><category>Apache Poi</category><category>Asp.net</category><category>Autofill</category><category>Batch File</category><category>Cells</category><category>Combobox</category><category>Concatenation</category><category>Count</category><category>Countif</category><category>Curl</category><category>Database</category><category>Dataframe</category><category>Date Range</category><category>Decimal</category><category>Drag</category><category>Duplicates</category><category>Excel 2003</category><category>Excel 2011</category><category>Excel 2013</category><category>Filter</category><category>Formatted</category><category>Function</category><category>Html</category><category>Indexing</category><category>Jasper Reports</category><category>Javascript</category><category>Laravel 5.1</category><category>Levenshtein Distance</category><category>Macos</category><category>Match</category><category>Ms Word</category><category>Numbers</category><category>Office Interop</category><category>Openpyxl</category><category>Parentheses</category><category>Parsing</category><category>Pivot Table</category><category>Powerpoint</category><category>Powerquery</category><category>Powershell</category><category>Put</category><category>R</category><category>Readonly</category><category>Reporting Services</category><category>Rest</category><category>Sas</category><category>Selection</category><category>Sql Server</category><category>Ssrs Tablix</category><category>String</category><category>Substring</category><category>Timestamp</category><category>Updates</category><category>Userform</category><category>Vbscript</category><category>Vlookup</category><category>Web Scraping</category><category>Webcam</category><category>Win32com</category><category>Worksheet</category><category>Xml</category><category>Xmlhttprequest</category><title>rrscils598f08</title><description></description><link>https://rrscils598f08.blogspot.com/</link><managingEditor>noreply@blogger.com (Mitchell Kassulke)</managingEditor><generator>Blogger</generator><openSearch:totalResults>105</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><language>en-us</language><itunes:explicit>no</itunes:explicit><itunes:summary>My podcast for Rutgers SCILS598 fall '08.</itunes:summary><itunes:subtitle>just another test podcast for a tech class</itunes:subtitle><itunes:category text="Education"><itunes:category text="Educational Technology"/></itunes:category><itunes:owner><itunes:email>rrscils598f08@gmail.com</itunes:email></itunes:owner><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-2671025934689915725</guid><pubDate>Sun, 01 Oct 2023 06:09:00 +0000</pubDate><atom:updated>2023-09-30T23:09:29.383-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Which Is Faster And More Efficient - For Loop, Match, Find, Etc?</title><description>&lt;div class="question"&gt;What I am doing is search some strings one by one in the entire range - like search for 'blah1', if found then exit, else search 'blah2' in the entire range in the same manner.  'b&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Try this one. Since your code is repeated (for "blah1" and "blah2") I used additional function:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; test()
    &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; Sheet1.Cells(&lt;span class="hljs-number"&gt;1&lt;/span&gt;, &lt;span class="hljs-string"&gt;"B"&lt;/span&gt;) = &lt;span class="hljs-string"&gt;""&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt; findString(&lt;span class="hljs-string"&gt;"blah1"&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Exit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt; findString(&lt;span class="hljs-string"&gt;"blah2"&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Exit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-comment"&gt;'Function findString returns TRUE if something found and FALSE otherwise&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt; findString(searchString &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Boolean&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; rng &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, res

    &lt;span class="hljs-keyword"&gt;With&lt;/span&gt; Sheet1
        &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rng = .Range(&lt;span class="hljs-string"&gt;"A1:A"&lt;/span&gt; &amp;amp; .Cells(.Rows.Count, &lt;span class="hljs-string"&gt;"A"&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;(xlUp).Row)

        res = Application.Match(searchString, rng, &lt;span class="hljs-number"&gt;0&lt;/span&gt;)
        &lt;span class="hljs-comment"&gt;'Application.Match returns error if nothing found&lt;/span&gt;
        findString = &lt;span class="hljs-built_in"&gt;Not&lt;/span&gt; IsError(res)
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; findString &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
            .Cells(&lt;span class="hljs-number"&gt;1&lt;/span&gt;, &lt;span class="hljs-string"&gt;"B"&lt;/span&gt;).Value = rng.Cells(res, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).Row
            .Cells(&lt;span class="hljs-number"&gt;1&lt;/span&gt;, &lt;span class="hljs-string"&gt;"C"&lt;/span&gt;).Value = searchString
        &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc" style="height: auto !important;"&gt;&lt;p&gt;I'm reasonably new to Excel Vba, but my limited understanding is that reading from cells is relatively slow. If I were doing this I would read all the values into an array, and carry out the same for loop as you have used, but on the array, rather than cell values. &lt;/p&gt;&lt;p&gt;To confirm, you could use VBAs Timer function to check speed. &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;Let me know if you'd like more detailed explanations of how to do this. &lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Here's how you can turn a range into an array (and vice versa). Step through this code with the Locals window turned on and watch what happens. You are particularly interested in the &lt;strong&gt;&lt;em&gt;astrArray&lt;/em&gt;&lt;/strong&gt; variable.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-csharp"&gt;&lt;span class="hljs-function"&gt;Sub &lt;span class="hljs-title"&gt;ChangeArray&lt;/span&gt;()
'
    Dim astrArray As Variant
'
'   Dim astrArray
'       that &lt;span class="hljs-keyword"&gt;is&lt;/span&gt;, &lt;span class="hljs-keyword"&gt;with&lt;/span&gt; no type specified
'       &lt;span class="hljs-keyword"&gt;is&lt;/span&gt; exactly equivalent
'
    Dim lngIndex As Long
    Dim strMessage As String
'
    &lt;span class="hljs-title"&gt;Range&lt;/span&gt;(&lt;span class="hljs-params"&gt;&lt;span class="hljs-string"&gt;"A1"&lt;/span&gt;&lt;/span&gt;).Value&lt;/span&gt; = &lt;span class="hljs-string"&gt;"This"&lt;/span&gt;
    Range(&lt;span class="hljs-string"&gt;"A2"&lt;/span&gt;).Value = &lt;span class="hljs-string"&gt;"is"&lt;/span&gt;
    Range(&lt;span class="hljs-string"&gt;"A3"&lt;/span&gt;).Value = &lt;span class="hljs-string"&gt;"only"&lt;/span&gt;
    Range(&lt;span class="hljs-string"&gt;"A4"&lt;/span&gt;).Value = &lt;span class="hljs-string"&gt;"a"&lt;/span&gt;
    Range(&lt;span class="hljs-string"&gt;"A5"&lt;/span&gt;).Value = &lt;span class="hljs-string"&gt;"test"&lt;/span&gt;
    astrArray = Range(&lt;span class="hljs-string"&gt;"A1:A5"&lt;/span&gt;)
    For lngIndex = &lt;span class="hljs-number"&gt;1&lt;/span&gt; To &lt;span class="hljs-number"&gt;5&lt;/span&gt;
        strMessage = strMessage &amp;amp; astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) &amp;amp; &lt;span class="hljs-string"&gt;" "&lt;/span&gt;
        Select Case lngIndex
            Case &lt;span class="hljs-number"&gt;1&lt;/span&gt;
                astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = &lt;span class="hljs-string"&gt;"No,"&lt;/span&gt;
            Case &lt;span class="hljs-number"&gt;2&lt;/span&gt;
                astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = &lt;span class="hljs-string"&gt;"it's"&lt;/span&gt;
            Case &lt;span class="hljs-number"&gt;3&lt;/span&gt;
                astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = &lt;span class="hljs-string"&gt;"actually"&lt;/span&gt;
            Case &lt;span class="hljs-number"&gt;4&lt;/span&gt;
                astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = &lt;span class="hljs-string"&gt;"real"&lt;/span&gt;
            Case &lt;span class="hljs-number"&gt;5&lt;/span&gt;
                astrArray(lngIndex, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = &lt;span class="hljs-string"&gt;"life"&lt;/span&gt;&lt;span class="hljs-function"&gt;End Select
    Next lngIndex
    MsgBox strMessage
    &lt;span class="hljs-title"&gt;Range&lt;/span&gt;(&lt;span class="hljs-params"&gt;&lt;span class="hljs-string"&gt;"A1:A5"&lt;/span&gt;&lt;/span&gt;)&lt;/span&gt; = astrArray
End Sub
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;A key requirement: to do this, the variable must be DIMmed Variant!&lt;/p&gt;&lt;p&gt;Another thing to pay attention to: the variable is two-dimensional, even though the range selected is one-dimensional.&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/which-is-faster-and-more-efficient-for.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8310816827313682091</guid><pubDate>Sat, 30 Sep 2023 23:44:00 +0000</pubDate><atom:updated>2023-09-30T16:44:52.063-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Count</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Count Cells With Values In A Column Up To Two Above The Active Cell, Excluding The Header</title><description>&lt;div class="question"&gt;I'm trying to count all the cells in a column that have values above the active cell excluding the header and excluding the cell immediately above the active cell. For example if I&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

 &lt;/h2&gt;&lt;div class="answer-desc" style="height: auto !important;"&gt;&lt;p&gt;Try this:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; counter()

&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; col &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lastrow &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; cellcount &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; ActiveCell
    col = .Column
    lastrow = .Row - &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;

cellcount = &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cell &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ActiveSheet.Range(Cells(&lt;span class="hljs-number"&gt;2&lt;/span&gt;, col), Cells(lastrow, col))

    &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; IsError(cell) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;GoTo&lt;/span&gt; skipcell

    &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; cell.Value &amp;gt; &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-built_in"&gt;And&lt;/span&gt; IsNumeric(cell) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; cellcount = cellcount + &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-symbol"&gt;skipcell:&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt; cell

ActiveCell = cellcount

&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;It takes the active cell and finds the selected colum and find the cell two above the active cell.&lt;/p&gt;&lt;p&gt;It then loops though the range adding to a counter each time it finds a value higher than "0"&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;As requested by OP in comments added in checks to ensure date in the cell is Numeric and that there is not a error (#N/A) value in the cell&lt;/p&gt;&lt;p&gt;Also requested is for this to span 260 columns in the same row. For this, use of a &lt;code&gt;for&lt;/code&gt; loop is employed:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_2" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; counter()

&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; firstCol &lt;span class="hljs-keyword"&gt;as&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;dim&lt;/span&gt; lastCol &lt;span class="hljs-keyword"&gt;as&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;

firstCol = &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-comment"&gt;'You can change this value depending on your first column&lt;/span&gt;&lt;span class="hljs-comment"&gt;' for example you might use ActiveCell.Column&lt;/span&gt;

lastCol = firstCol + &lt;span class="hljs-number"&gt;260&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; col &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lastrow &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;
lastRow = &lt;span class="hljs-number"&gt;6&lt;/span&gt;&lt;span class="hljs-comment"&gt;' Make this the actual last row of the data to include&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; cellcount &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;for&lt;/span&gt; col = firstCol &lt;span class="hljs-keyword"&gt;to&lt;/span&gt; lastCol

    cellcount = &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cell &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ActiveSheet.Range(Cells(&lt;span class="hljs-number"&gt;2&lt;/span&gt;, col), Cells(lastrow, col))

        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; IsError(cell) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;GoTo&lt;/span&gt; skipcell

        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; cell.Value &amp;gt; &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-built_in"&gt;And&lt;/span&gt; IsNumeric(cell) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; cellcount = cellcount + &lt;span class="hljs-number"&gt;1&lt;/span&gt;

    skipcell:

    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt; cell

    ActiveSheet.Cells(lastRow + &lt;span class="hljs-number"&gt;2&lt;/span&gt;, col) = cellcount

&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt; col

&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_2')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Why does this have to be VBA code?&lt;/p&gt;&lt;p&gt;It is very simple to do in a cell formula:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-bash"&gt;=COUNTIF(A1:A5,&lt;span class="hljs-string"&gt;"&amp;lt;&amp;gt;0"&lt;/span&gt;)-2
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;This counts all the cells in the given range (&lt;code&gt;A1:A5&lt;/code&gt;) which are not equal to zero. Since you know you want to remove the header row and one row above, subtract 2 from the answer. Of course, this the same as &lt;/p&gt;&lt;pre&gt;&lt;code id="code_5" class="hljs language-bash"&gt;=COUNTIF(A2:A4,&lt;span class="hljs-string"&gt;"&amp;lt;&amp;gt;0"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_5')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;If you want to use this in VBA then look into &lt;code&gt;WorksheetFunction&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_7" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; myCount &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;
myCount = WorksheetFunction.COUNTIF(ActiveSheet.Range(&lt;span class="hljs-string"&gt;"A2:A4"&lt;/span&gt;),&lt;span class="hljs-string"&gt;"&amp;lt;&amp;gt;0"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_7')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Then insert &lt;code&gt;myCount&lt;/code&gt; into the sheet&lt;/p&gt;&lt;pre&gt;&lt;code id="code_9" class="hljs language-bash"&gt;ActiveSheet.Range(&lt;span class="hljs-string"&gt;"A6"&lt;/span&gt;).value = myCount
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_9')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/count-cells-with-values-in-column-up-to.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8463316642083075450</guid><pubDate>Sat, 30 Sep 2023 23:09:00 +0000</pubDate><atom:updated>2023-09-30T16:09:23.634-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Cells</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Check Merged Cell And Compare Adjacent To Set Unique Value From Compared Cells Values</title><description>&lt;div class="question"&gt;I'm writing a macro in Excel 2010 for a problem that is as follows:  I have two columns, one with a Key string value and one with a uuid. The idea is that every key should have onl&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; CopyUUID()

    &lt;span class="hljs-keyword"&gt;Const&lt;/span&gt; UUID &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt; = &lt;span class="hljs-number"&gt;31&lt;/span&gt;&lt;span class="hljs-comment"&gt;'col AE&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lRow &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;, cel &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, isM &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Boolean&lt;/span&gt;, copyID &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Boolean&lt;/span&gt;, kCol &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; ActiveSheet
        kCol = -&lt;span class="hljs-number"&gt;25&lt;/span&gt;&lt;span class="hljs-comment"&gt;'col F&lt;/span&gt;
        lRow = .Cells(.Rows.Count, UUID + kCol).&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;(xlUp).Row

        &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cel &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; .Range(.Cells(&lt;span class="hljs-number"&gt;3&lt;/span&gt;, UUID), .Cells(lRow, UUID))

            isM = cel.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, kCol).MergeCells
            copyID = isM &lt;span class="hljs-built_in"&gt;And&lt;/span&gt; Len(cel.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, kCol)) = &lt;span class="hljs-number"&gt;0&lt;/span&gt;
            copyID = copyID &lt;span class="hljs-built_in"&gt;Or&lt;/span&gt; (&lt;span class="hljs-built_in"&gt;Not&lt;/span&gt; isM &lt;span class="hljs-built_in"&gt;And&lt;/span&gt; cel.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, kCol) = cel.Offset(-&lt;span class="hljs-number"&gt;1&lt;/span&gt;, kCol))

            &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; copyID &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; cel = cel.Offset(-&lt;span class="hljs-number"&gt;1&lt;/span&gt;)
        &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Try the following code. Note that this is going to overwrite the current contents of UUID, so make a backup copy before testing. If you don't want the UUID column modified, you can modify this to suit your needs.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-sql"&gt;Sub CopyUUID()
    Dim lRow &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Long
    Dim rng &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;
    Dim c &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;
    Dim ws &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet
    Dim rMerged &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;
    Dim &lt;span class="hljs-keyword"&gt;value&lt;/span&gt;&lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Variant

    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; ws &lt;span class="hljs-operator"&gt;=&lt;/span&gt; Sheets(ActiveSheet.Name)

    &lt;span class="hljs-keyword"&gt;On&lt;/span&gt; Error GoTo ExitProgram &lt;span class="hljs-string"&gt;'If an error happens within the execution, skips it and continue in next step
    '&lt;/span&gt; Application.DisplayAlerts &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-literal"&gt;False&lt;/span&gt;&lt;span class="hljs-string"&gt;'We can cancel the procedure without errors

    With ws
        lRow = .Range("F" &amp;amp; .Rows.Count).End(xlUp).Row
        Set rng = .Range(.Cells(3, 6), .Cells(lRow, 6))
        '&lt;/span&gt; rng.Select
        &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; c &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; rng

            If c.MergeCells &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-string"&gt;'Code for merged cells
                c.Offset(0, 1).Formula = c.MergeArea.Cells(1, 1).Offset(0, 1).Formula
            Else
                '&lt;/span&gt;Code &lt;span class="hljs-keyword"&gt;to&lt;/span&gt; use &lt;span class="hljs-keyword"&gt;for&lt;/span&gt; single cells
                If c.Formula &lt;span class="hljs-operator"&gt;=&lt;/span&gt; c.Offset(&lt;span class="hljs-number"&gt;-1&lt;/span&gt;, &lt;span class="hljs-number"&gt;0&lt;/span&gt;).Formula &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
                    c.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).Formula &lt;span class="hljs-operator"&gt;=&lt;/span&gt; c.Offset(&lt;span class="hljs-number"&gt;-1&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).Formula
                &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If
            &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If
        Next c
    &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;
    ExitProgram:
       Exit Sub
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt; Sub
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;When in a MergedCell, it makes the UUID the same as the UUID of the first cell in the merged area. When not in a MergedCell, it copies UUID from the row above if Key is the same as the row above.&lt;/p&gt;&lt;p&gt;I changed your variable &lt;code&gt;cell&lt;/code&gt; to &lt;code&gt;c&lt;/code&gt; (I don't like to use variable names that can be confused with built-ins) and commented out a couple of lines. &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;Hope this helps&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I adopt a simple approach to this problem as illustrated through steps taken by me.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;sample sheet showing data with merged cells and unmerged cells.
&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/u2XzV.jpg"&gt;&lt;img alt="sample data" src="https://i.stack.imgur.com/u2XzV.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Run the program code to unmerge the cells. Output of the program is appended below.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/YbYkl.jpg"&gt;&lt;img alt="Unmerged Sample data First stage" src="https://i.stack.imgur.com/YbYkl.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;ol start="3"&gt;&lt;li&gt;If this structure of data matches your case then addition of 2 lines of code for column B will leave the data as per following image.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/ukAQO.jpg"&gt;&lt;img alt="unmerged data after deleting column through program code" src="https://i.stack.imgur.com/ukAQO.jpg"&gt;&lt;/a&gt;&lt;/p&gt;&lt;ol start="4"&gt;&lt;li&gt;Program code is as follows:&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;'Without column deletion:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_4" class="hljs language-sql"&gt;Sub UnMergeRanges()
    Dim cl &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;
    Dim rMerged &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;
    Dim v &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Variant

    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cl &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ActiveSheet.UsedRange
        If cl.MergeCells &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rMerged &lt;span class="hljs-operator"&gt;=&lt;/span&gt; cl.MergeArea
            v &lt;span class="hljs-operator"&gt;=&lt;/span&gt; rMerged.Cells(&lt;span class="hljs-number"&gt;1&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;)
            rMerged.MergeCells &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-literal"&gt;False&lt;/span&gt;
            rMerged &lt;span class="hljs-operator"&gt;=&lt;/span&gt; v
        &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If
    Next
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt; Sub
&lt;span class="hljs-string"&gt;'With coumn deletion   
Sub UnMergeRangesB()
    Dim cl As Range
    Dim rMerged As Range
    Dim v As Variant

    For Each cl In ActiveSheet.UsedRange
        If cl.MergeCells Then
            Set rMerged = cl.MergeArea
            v = rMerged.Cells(1, 1)
            rMerged.MergeCells = False
            rMerged = v
        End If
    Next
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
End Sub
&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_4')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/check-merged-cell-and-compare-adjacent.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-6443369279273614489</guid><pubDate>Sat, 30 Sep 2023 22:31:00 +0000</pubDate><atom:updated>2023-09-30T15:31:48.212-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>What's The Best Way To Compare Two Sheets In An Excel Workbook</title><description>&lt;div class="question"&gt;Given I have the following &lt;Sheet 1&gt; Item    QTY A        5 B        1 C        3   &lt;Sheet 2&gt; Item    QTY A        15 B        4 C        1 D        8  What is the best&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;You shouldn't need VBA for this.&lt;/p&gt;&lt;p&gt;Here's what you do:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Create a new worksheet (Sheet3).&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Set it up to look like this:&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://img16.imageshack.us/img16/2451/consolidationsheet.jpg"&gt;alt text http://img16.imageshack.us/img16/2451/consolidationsheet.jpg&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Here are the formulas you will need (paste each one into the proper cell):&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; the first two are "array formulas" -- after you paste in the formula, double-click the cell and do Ctrl-Shift-Enter (braces {} should appear around the formula)&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-sql"&gt;&lt;span class="hljs-comment"&gt;------------------------------------------------------------------------------&lt;/span&gt;
Cell Formula
&lt;span class="hljs-comment"&gt;------------------------------------------------------------------------------&lt;/span&gt;
 B2  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-built_in"&gt;SUM&lt;/span&gt;(IF(Sheet1&lt;span class="hljs-operator"&gt;!&lt;/span&gt;A:A&lt;span class="hljs-operator"&gt;=&lt;/span&gt;"",&lt;span class="hljs-number"&gt;0&lt;/span&gt;,&lt;span class="hljs-number"&gt;1&lt;/span&gt;)) &lt;span class="hljs-operator"&gt;&amp;lt;&lt;/span&gt;&lt;span class="hljs-comment"&gt;-- array formula: use Ctrl-Shift-Enter instead of Enter&lt;/span&gt;
 B3  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-built_in"&gt;SUM&lt;/span&gt;(IF(Sheet2&lt;span class="hljs-operator"&gt;!&lt;/span&gt;A:A&lt;span class="hljs-operator"&gt;=&lt;/span&gt;"",&lt;span class="hljs-number"&gt;0&lt;/span&gt;,&lt;span class="hljs-number"&gt;1&lt;/span&gt;)) &lt;span class="hljs-operator"&gt;&amp;lt;&lt;/span&gt;&lt;span class="hljs-comment"&gt;-- array formula: use Ctrl-Shift-Enter instead of Enter            &lt;/span&gt;
 D2  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;IF(D1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;D$&lt;span class="hljs-number"&gt;1&lt;/span&gt;,&lt;span class="hljs-number"&gt;2&lt;/span&gt;,IF(&lt;span class="hljs-keyword"&gt;OR&lt;/span&gt;(D1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;B$&lt;span class="hljs-number"&gt;2&lt;/span&gt;,D1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;""),"",D1&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;))
 E2  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;IF(D2&lt;span class="hljs-operator"&gt;=&lt;/span&gt;"",IF(D1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;"",IF(&lt;span class="hljs-keyword"&gt;OR&lt;/span&gt;(E1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;B$&lt;span class="hljs-number"&gt;3&lt;/span&gt;,E1&lt;span class="hljs-operator"&gt;=&lt;/span&gt;""),"",E1&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;),&lt;span class="hljs-number"&gt;2&lt;/span&gt;),"")
 G2  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;IF(D2&lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt;"",INDEX(Sheet1&lt;span class="hljs-operator"&gt;!&lt;/span&gt;A:A,D2),IF(E2&lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt;"",INDEX(Sheet2&lt;span class="hljs-operator"&gt;!&lt;/span&gt;A:A,E2),""))
 H2  &lt;span class="hljs-operator"&gt;=&lt;/span&gt;IF(D2&lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt;"",&lt;span class="hljs-operator"&gt;-&lt;/span&gt;INDEX(Sheet1&lt;span class="hljs-operator"&gt;!&lt;/span&gt;B:B,D2),IF(E2&lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt;"",INDEX(Sheet2&lt;span class="hljs-operator"&gt;!&lt;/span&gt;B:B,E2),""))
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Drag the formulas in D2:H2 down as far as you need to cover all the data for sheets 1 and 2.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Select all the data in columns G &amp;amp; H (including the headings).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Do Insert &amp;gt; PivotTable and click OK.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Click the Pivot Table and drag &lt;code&gt;[]Item&lt;/code&gt; to the Row Labels box and &lt;code&gt;[]QTY&lt;/code&gt; to the Values box.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;That's it. The Pivot Table will contain a summary for each item. No item will be repeated, and no item will be left out. The "Sum of QTY" column will actually contain the difference (since the formula uses negative for all sheet 1 quantities).&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;In Excel VBA, use a &lt;a rel="nofollow noreferrer noopener" href="https://stackoverflow.com/questions/915317/does-vba-have-dictionary-structure"&gt;Dictionary&lt;/a&gt;. Use your items from one of the sheets as keys, QTY as values. Put the item/QTY pairs of sheet 1 into the dictionary, then run through the items of sheet 2 update the dictionary accordingly to get the differences in there. Finally, put the result into sheet 3.&lt;/p&gt;&lt;p&gt;EDIT: here is a complete example in code (you have to set a reference to the Microsoft Scripting runtime to get it working this way):&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; CreateDiff()

    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; dict &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-built_in"&gt;New&lt;/span&gt; Dictionary
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; sh1 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet, sh2 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet, sh3 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; i &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;, v &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; sh1 = ThisWorkbook.Sheets(&lt;span class="hljs-string"&gt;"Sheet1"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; sh2 = ThisWorkbook.Sheets(&lt;span class="hljs-string"&gt;"Sheet2"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; sh3 = ThisWorkbook.Sheets(&lt;span class="hljs-string"&gt;"Sheet3"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; sh1.Cells.SpecialCells(xlCellTypeLastCell).Row
        v = Trim(sh1.Cells(i, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).Value)
        dict(v) = -sh1.Cells(i, &lt;span class="hljs-number"&gt;2&lt;/span&gt;).Value
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; sh2.Cells.SpecialCells(xlCellTypeLastCell).Row
        v = Trim(sh2.Cells(i, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).Value)
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; dict.Exists(v) &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
            dict(v) = dict(v) + sh2.Cells(i, &lt;span class="hljs-number"&gt;2&lt;/span&gt;).Value
        &lt;span class="hljs-keyword"&gt;Else&lt;/span&gt;
            dict(v) = sh2.Cells(i, &lt;span class="hljs-number"&gt;2&lt;/span&gt;).Value
        &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; dict.Count - &lt;span class="hljs-number"&gt;1&lt;/span&gt;
        v = dict.Keys(i)
        sh3.Cells(i + &lt;span class="hljs-number"&gt;2&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = v
        sh3.Cells(i + &lt;span class="hljs-number"&gt;2&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;) = dict(v)
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;you could merge both sets of data onto a single sheet side-by-side (item1, qty, item2, qty) then use the VLOOKUP() excel function to find the data from the opposite set.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_4"&gt;Solution 4:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;One possibility is to use ADO&lt;/p&gt;&lt;pre&gt;&lt;code id="code_4" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; cn &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Object&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; rs &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Object&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; strFile &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; strCon &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; strSQL &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-comment"&gt;''http://support.microsoft.com/kb/246335&lt;/span&gt;

strFile = Workbooks(&lt;span class="hljs-string"&gt;"Book1.xls"&lt;/span&gt;).FullName

&lt;span class="hljs-comment"&gt;''Note HDR=Yes, the names in the first row of the range&lt;/span&gt;&lt;span class="hljs-comment"&gt;''can be used.&lt;/span&gt;
strCon = &lt;span class="hljs-string"&gt;"Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&lt;/span&gt; &amp;amp; strFile _
    &amp;amp; &lt;span class="hljs-string"&gt;";Extended Properties=""Excel 8.0;HDR=Yes;IMEX=1"";"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; cn = CreateObject(&lt;span class="hljs-string"&gt;"ADODB.Connection"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rs = CreateObject(&lt;span class="hljs-string"&gt;"ADODB.Recordset"&lt;/span&gt;)

cn.Open strCon

strSQL = &lt;span class="hljs-string"&gt;"SELECT s2.Item, s2.Qty-IIf(s1.Qty Is Null,0,s1.Qty) FROM [Sheet2$] s2 "&lt;/span&gt; _
&amp;amp; &lt;span class="hljs-string"&gt;"LEFT JOIN [Sheet1$] s1 ON s2.Item=s1.Item"&lt;/span&gt;

rs.Open strSQL, cn, &lt;span class="hljs-number"&gt;3&lt;/span&gt;, &lt;span class="hljs-number"&gt;3&lt;/span&gt;

Workbooks(&lt;span class="hljs-string"&gt;"Book1.xls"&lt;/span&gt;).Worksheets(&lt;span class="hljs-string"&gt;"Sheet3"&lt;/span&gt;).Cells(&lt;span class="hljs-number"&gt;2&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).CopyFromRecordset rs
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_4')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_5"&gt;Solution 5:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Why use VBA?
On Sheet 3 comparison sheet list all possible items from sheets 1 and 2 in column A then in Column B use the following formula. Starting in B2 then copy down.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;=if(iserror(vlookup(A2,Sheet2'$A$2:$B$5,2,false),0,vlookup(A2,Sheet2'$A$2:$B$5,2,false))-if(iserror(vlookup(A2,Sheet1'$A$2:$B$5,2,false),0,vlookup(A2,Sheet1'$A$2:$B$5,2,false))&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Change the table range as necessary.&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/whats-best-way-to-compare-two-sheets-in.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-6552665176161325777</guid><pubDate>Sat, 30 Sep 2023 21:46:00 +0000</pubDate><atom:updated>2023-09-30T14:46:46.122-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Excel Formula</category><title>Is It Possible To Mimic Excel Rows In A Different Sheet?</title><description>&lt;div class="question"&gt;So in 'Sheet 1' I have 2000 rows of information which I add a new column to every day, I want to have only a subset of the rows of 'Sheet 1' in 'Sheet 2' which update themselves as&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;If you want to select a set of particular rows and you know their row numbers, put their row numbers (1,5,8,11,12 ...) in a separate 1 column range and name this range e.g. "RowNumbers"&lt;/p&gt;&lt;p&gt;Then use following normal non-array formula which you can drag downwards and rightwards. &lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-sql"&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; IF(INDEX(RowNumbers,&lt;span class="hljs-type"&gt;ROW&lt;/span&gt;(A1)&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;)&lt;span class="hljs-operator"&gt;&amp;gt;&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;, INDEX(NamedRange,INDEX(RowNumbers,&lt;span class="hljs-type"&gt;ROW&lt;/span&gt;(A1)&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;),&lt;span class="hljs-keyword"&gt;COLUMN&lt;/span&gt;(B1)&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;),"")
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You will probably need to adjust the &lt;code&gt;+1&lt;/code&gt; parts, depending on whether your values start at row 1 or 2 etc.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;Basically the Excel &lt;code&gt;INDEX&lt;/code&gt; formula does what you need - copies the value from another sheet or range by given row and column numbers.&lt;/p&gt;&lt;hr&gt;&lt;p&gt;Otherwise you can use following &lt;strong&gt;array formula&lt;/strong&gt; (Ctrl+Shift+Enter) to select filtered values from columns based on multiple criteria:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-sql"&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; IFERROR(INDEX(NamedRange,
   SMALL(IF((INDEX(NamedRange,,&lt;span class="hljs-number"&gt;1&lt;/span&gt;,&lt;span class="hljs-number"&gt;1&lt;/span&gt;)&lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;)&lt;span class="hljs-operator"&gt;*&lt;/span&gt;(INDEX(NamedRange,,&lt;span class="hljs-number"&gt;2&lt;/span&gt;,&lt;span class="hljs-number"&gt;1&lt;/span&gt;)&lt;span class="hljs-operator"&gt;=&lt;/span&gt;"A"),
   &lt;span class="hljs-type"&gt;ROW&lt;/span&gt;(NamedRange)&lt;span class="hljs-operator"&gt;-&lt;/span&gt;&lt;span class="hljs-built_in"&gt;MIN&lt;/span&gt;(&lt;span class="hljs-type"&gt;ROW&lt;/span&gt;(NamedRange))&lt;span class="hljs-operator"&gt;+&lt;/span&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;,""),
   &lt;span class="hljs-keyword"&gt;ROWS&lt;/span&gt;(C1:$C$&lt;span class="hljs-number"&gt;1&lt;/span&gt;)),&lt;span class="hljs-number"&gt;3&lt;/span&gt;,&lt;span class="hljs-number"&gt;1&lt;/span&gt;),"")
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;img alt="FormulaDesc" src="https://i.stack.imgur.com/3HuSe.jpg"&gt;&lt;/p&gt;&lt;p&gt;Here is an example data sheet (Sheet1)&lt;/p&gt;&lt;p&gt;&lt;img alt="Sheet1" src="https://i.stack.imgur.com/SpJYn.jpg"&gt;&lt;/p&gt;&lt;p&gt;Here is the filtered data output sheet. You should enter the array formula in the first row and drag downwards to fill expected output range. In this example I select only rowns that have values &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;A&lt;/code&gt; ind &lt;code&gt;filter1&lt;/code&gt; and &lt;code&gt;filter2&lt;/code&gt; columns.&lt;/p&gt;&lt;p&gt;&lt;img alt="Sheet2" src="https://i.stack.imgur.com/rpozO.jpg"&gt;&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/is-it-possible-to-mimic-excel-rows-in.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-2692669666241902794</guid><pubDate>Sat, 30 Sep 2023 20:22:00 +0000</pubDate><atom:updated>2023-09-30T13:22:11.180-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba To Find Multiple Files</title><description>&lt;div class="question"&gt;I have this code which finds file names(along with file paths) based on search string.This code works fine in finding single files. I would like this macro to find multiple files a&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I realize this question is very old, but it is unanswered. Here is a quick method for finding multiple files and their paths. VBA's &lt;code&gt;DIR&lt;/code&gt; function isn't really very handy, but CMD's &lt;a rel="nofollow noreferrer noopener" href="https://ss64.com/nt/dir.html"&gt;&lt;code&gt;DIR&lt;/code&gt; function&lt;/a&gt; is well optimized and has a plethora of command line switches to make it return only files (or even just folders) that match your criteria. The trick is to &lt;a rel="nofollow noreferrer noopener" href="https://blogs.technet.microsoft.com/heyscriptingguy/2004/08/10/how-can-i-call-the-dir-command/"&gt;call &lt;code&gt;DIR&lt;/code&gt;from a WScript shell&lt;/a&gt; so that the output can be parsed by VBA.&lt;/p&gt;&lt;p&gt;For example, this snippet of code will find every file on your system that starts with &lt;em&gt;config&lt;/em&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; oShell &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Object&lt;/span&gt;&lt;span class="hljs-comment"&gt;'New WshShell if you want early binding&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; cmd &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Object&lt;/span&gt;&lt;span class="hljs-comment"&gt;'WshExec if you want early binding&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; x &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Const&lt;/span&gt; WshRunning = &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; oShell = CreateObject(&lt;span class="hljs-string"&gt;"Wscript.Shell"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; cmd = oShell.Exec(&lt;span class="hljs-string"&gt;"cmd /c ""Dir c:\config* /a:-d /b /d /s"""&lt;/span&gt;)

&lt;span class="hljs-keyword"&gt;Do&lt;/span&gt;&lt;span class="hljs-keyword"&gt;While&lt;/span&gt; cmd.Status = WshRunning
    DoEvents
&lt;span class="hljs-keyword"&gt;Loop&lt;/span&gt;

Debug.Print cmd.StdOut.ReadAll
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; oShell = &lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; cmd = &lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-to-find-multiple-files.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8775830639342537686</guid><pubDate>Sat, 30 Sep 2023 18:55:00 +0000</pubDate><atom:updated>2023-09-30T11:55:36.473-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Arrays</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Excel Formula</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba - Long Array Formula Via Application.evaluate</title><description>&lt;div class="question"&gt;Say we have some long formula saved in cell A1: =SomeArrayFunction( IF(SUM(D3:D6)&gt;1,'A-B-C-D-E-F-G-H-I-J-K-L-M-N-O-P-Q-R-S-T-U-V-W-X 01', 'part_one'), IF(SUM(D3:D6)&gt;1,'A-B-C-&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc" style="height: auto !important;"&gt;&lt;p&gt;I believe that &lt;code&gt;Application.Evaluate&lt;/code&gt; will return a result that matches the size of the input address. I suspect that your &lt;code&gt;Selection&lt;/code&gt; is a single cell so it is returning a single value.&lt;/p&gt;&lt;p&gt;If instead you call it with &lt;code&gt;Selection.CurrentArray.Address&lt;/code&gt; you will get an answer that is the same size as the correct array.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Picture of VBA and Excel&lt;/strong&gt;&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;&lt;img alt="enter image description here" src="https://i.stack.imgur.com/1h2Rj.png"&gt;&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Code to test with&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-php"&gt;&lt;span class="hljs-keyword"&gt;Public&lt;/span&gt;&lt;span class="hljs-function"&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;span class="hljs-title"&gt;Test&lt;/span&gt;(&lt;span class="hljs-params"&gt;&lt;/span&gt;) &lt;span class="hljs-title"&gt;As&lt;/span&gt;&lt;span class="hljs-title"&gt;Variant&lt;/span&gt;&lt;span class="hljs-title"&gt;Test&lt;/span&gt; = &lt;span class="hljs-title"&gt;Array&lt;/span&gt;(&lt;span class="hljs-params"&gt;&lt;span class="hljs-number"&gt;1&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;/span&gt;)


&lt;span class="hljs-title"&gt;End&lt;/span&gt;&lt;span class="hljs-title"&gt;Function&lt;/span&gt;&lt;span class="hljs-title"&gt;Sub&lt;/span&gt;&lt;span class="hljs-title"&gt;t&lt;/span&gt;(&lt;span class="hljs-params"&gt;&lt;/span&gt;)

    &lt;span class="hljs-title"&gt;Dim&lt;/span&gt;&lt;span class="hljs-title"&gt;a&lt;/span&gt;&lt;span class="hljs-title"&gt;As&lt;/span&gt;&lt;span class="hljs-title"&gt;Variant&lt;/span&gt;&lt;span class="hljs-title"&gt;a&lt;/span&gt; = &lt;span class="hljs-title"&gt;Application&lt;/span&gt;.&lt;span class="hljs-title"&gt;Evaluate&lt;/span&gt;(&lt;span class="hljs-params"&gt;Selection.CurrentArray.Address&lt;/span&gt;)

&lt;span class="hljs-title"&gt;End&lt;/span&gt;&lt;span class="hljs-title"&gt;Sub&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Edit&lt;/strong&gt;, based on comments here is a way evaluate this off sheet by creating a new sheet. I am using a cut/paste approach to ensure the formulas all work the same. This probably works better if cells don't reference the cut one. It will technically not break any other cells though since I am using cut/paste.&lt;/p&gt;&lt;p&gt;In the code below, I had an array formula in cell &lt;code&gt;J2&lt;/code&gt; it referenced several other cells. It is expanded to have 3 rows and then the &lt;code&gt;Evaluate&lt;/code&gt; call is made. That returns an array like you want. It then shrinks it down to one cell and moves it back.&lt;/p&gt;&lt;p&gt;I have tested this for a simple example. I have no idea if it works for the application you have in mind.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_6" class="hljs language-rust"&gt;Sub &lt;span class="hljs-title function_ invoke__"&gt;EvaluateArrayFormulaOnNewSheet&lt;/span&gt;()

    &lt;span class="hljs-symbol"&gt;'cut&lt;/span&gt; cell with formula
    Dim str_address As &lt;span class="hljs-type"&gt;String&lt;/span&gt;
    Dim rng_start As Range
    Set rng_start = Sheet1.&lt;span class="hljs-title function_ invoke__"&gt;Range&lt;/span&gt;(&lt;span class="hljs-string"&gt;"J2"&lt;/span&gt;)
    str_address = rng_start.Address

    rng_start.Cut

    &lt;span class="hljs-symbol"&gt;'create&lt;/span&gt; new sheet
    Dim sht As Worksheet
    Set sht = Worksheets.Add

    &lt;span class="hljs-symbol"&gt;'paste&lt;/span&gt; cell onto sheet
    Dim rng_arr As Range
    Set rng_arr = sht.&lt;span class="hljs-title function_ invoke__"&gt;Range&lt;/span&gt;(&lt;span class="hljs-string"&gt;"A1"&lt;/span&gt;)
    sht.Paste rng_arr

    &lt;span class="hljs-symbol"&gt;'expand&lt;/span&gt; array formula size.. resize to whatever size is needed
    rng_arr.&lt;span class="hljs-title function_ invoke__"&gt;Resize&lt;/span&gt;(&lt;span class="hljs-number"&gt;3&lt;/span&gt;).FormulaArray = rng_arr.FormulaArray

    &lt;span class="hljs-symbol"&gt;'get&lt;/span&gt; your result
    Dim v_arr As Variant
    v_arr = Application.&lt;span class="hljs-title function_ invoke__"&gt;Evaluate&lt;/span&gt;(rng_arr.CurrentArray.Address)

    &lt;span class="hljs-string"&gt;'''&lt;/span&gt;&lt;span class="hljs-symbol"&gt;'do&lt;/span&gt; something with your result here... it is an array


    &lt;span class="hljs-symbol"&gt;'shrink&lt;/span&gt; the formula back to one cell
    Dim str_formula As &lt;span class="hljs-type"&gt;String&lt;/span&gt;
    str_formula = rng_arr.FormulaArray

    rng_arr.CurrentArray.ClearContents
    rng_arr.FormulaArray = str_formula

    &lt;span class="hljs-symbol"&gt;'cut&lt;/span&gt; and paste back to original spot
    rng_arr.Cut

    Sheet1.Paste Sheet1.&lt;span class="hljs-title function_ invoke__"&gt;Range&lt;/span&gt;(str_address)

    Application.DisplayAlerts = False
    sht.Delete
    Application.DisplayAlerts = True

End Sub
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_6')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Try&lt;/p&gt;&lt;pre&gt;&lt;code id="code_7" class="hljs language-ini"&gt;&lt;span class="hljs-attr"&gt;vOutput&lt;/span&gt; = Application.Evaluate(Selection.CurrentArray.Address)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_7')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;(assuming you have two cells with &lt;code&gt;=SomeArrayFunction(...)&lt;/code&gt; entered as an array formula)&lt;/p&gt;&lt;p&gt;I think the difference may be that evaluating a single cell will only get you the values returned &lt;em&gt;to that cell&lt;/em&gt;: the whole array isn't returned there, only the first value.&lt;/p&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-long-array-formula-via.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-7025308963144076058</guid><pubDate>Sat, 30 Sep 2023 18:12:00 +0000</pubDate><atom:updated>2023-09-30T11:12:26.325-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Excel Vba - Open Files With Variable (dates) Filenames</title><description>&lt;div class="question"&gt;I have the below code to open up files with variable file names, due to dates being in them.  I personally save each file daily with the date stamp, ie this morning I saved a file&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;blockquote&gt;&lt;p&gt;That a file exists for last Thursday, yet my code tells me there is none&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;As &lt;a rel="nofollow noreferrer noopener" href="https://stackoverflow.com/questions/43497439/excel-vba-append-xls-to-filename-to-open-file#comment74091822_43497492"&gt;I explained in the other question you asked yesterday&lt;/a&gt;, putting the &lt;code&gt;vbMonday&lt;/code&gt; or &lt;code&gt;vbThursday&lt;/code&gt; etc in the &lt;code&gt;Format&lt;/code&gt; function doesn't magically tell VBA to return that day:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Hint: The &lt;code&gt;vbFriday&lt;/code&gt; part of the Weekday function is not magically telling it to get friday's date. It's actually telling it that, for the sake of this function call, consider Friday to be the first day of the week. The &lt;code&gt;Weekday&lt;/code&gt; function then returns an integer (the ordinal day of the week) which it subtracts from the &lt;code&gt;Date&lt;/code&gt;.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/blockquote&gt;&lt;p&gt;So, you need to go back and understand how those functions work, you can't just dump constants in there willy-nilly without making an effort to understand what they're doing, or why. On that note, you absolutely need to &lt;a rel="nofollow noreferrer noopener" href="http://www.cpearson.com/excel/DebuggingVBA.aspx"&gt;read this and learn how to begin debugging and troubleshooting first&lt;/a&gt;. This describes basics of how to step through your code and examine variable's values/etc at runtime. These techniques are foundations you need to work with VBA.&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://msdn.microsoft.com/en-us/library/office/jj692812(v=office.15).aspx"&gt;Here&lt;/a&gt; is a list of statements available in VBA. This is documentation that explains things like "How to create a loop structure with &lt;code&gt;For/Next&lt;/code&gt;, etc."&lt;/p&gt;&lt;p&gt;And you should go back through the dozen or so questions you've asked here, and mark accepted answers for those where an answer has solved your problem. This is just a basic point of etiquette: You've asked 11 questions here and only accepted 1 answer.&lt;/p&gt;&lt;p&gt;Note also that this sort of declaration does not do what you think it does:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_7" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; LastFridayDate, MondayDate, TuesdayDate, WednesdayDate, ThursdayDate &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; fullFileNameLastFriday, fullFileNameMonday, fullFileNameTuesday, fullFileNameWednesday, fullFileNameThursday &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; wbkLastFriday, wbkMonday, wbkTuesday, wbkWednesday, wbkThursdayOpen &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_7')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Only the last item in each of those statements are strongly typed, the rest are implicitly variant. You should strongly type all variables when possible, e.g.:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_8" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; wbkLastFriday &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook, wbkMonday &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook, wbkTuesday &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook, wbkWednesday &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook, wbkThursdayOpen &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Workbook
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_8')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;And rather than using five different workbook objects (unless you really need 5 workbooks open at once, just use a single workbook object and operate within a loop, opening successive file at each iteration.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_9" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; wb &lt;span class="hljs-keyword"&gt;as&lt;/span&gt; Workbook
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; i &lt;span class="hljs-keyword"&gt;as&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;to&lt;/span&gt;&lt;span class="hljs-number"&gt;5&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; wb = Workbooks.Open(...)
    &lt;span class="hljs-comment"&gt;'Do something&lt;/span&gt;
    wb.Close()
&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_9')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;hr&gt;&lt;p&gt;Getting to your actual problem:&lt;/p&gt;&lt;p&gt;A function like below will return an array of your date components. This returns the previous 7 days from the &lt;em&gt;FirstDay&lt;/em&gt; (which defaults to Friday previous). You can use the &lt;code&gt;Dir&lt;/code&gt; function as previously to simply test whether a filename is valid/existing (e.g., Sunday file doesn't exist, etc.), and skip over it if it's not valid.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_11" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt; GetFileNames(&lt;span class="hljs-keyword"&gt;Optional&lt;/span&gt; FirstDay = vbFriday)
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; filenames(&lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt;&lt;span class="hljs-number"&gt;7&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; i &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt;&lt;span class="hljs-number"&gt;7&lt;/span&gt;
filenames(i) = Format(&lt;span class="hljs-type"&gt;Date&lt;/span&gt; - (Weekday(&lt;span class="hljs-type"&gt;Date&lt;/span&gt;, FirstDay) + i), &lt;span class="hljs-string"&gt;"m.d.yy"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;
GetFileNames = filenames
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_11')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;It seems that you want your search to start from &lt;em&gt;yesterday&lt;/em&gt; instead of today. If so, you can try changing&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;code&gt;ThursdayDate = Format(Date - (Weekday(Date, vbThursday) - 1), "m.d.yy")&lt;/code&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;into&lt;/p&gt;&lt;pre&gt;&lt;code id="code_13" class="hljs language-ini"&gt;&lt;span class="hljs-attr"&gt;ThursdayDate&lt;/span&gt; = Format(Date - (Weekday(Date - &lt;span class="hljs-number"&gt;1&lt;/span&gt;, vbThursday)), &lt;span class="hljs-string"&gt;"m.d.yy"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_13')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;and generalize it to other week days. In fact what it does now is that when it runs, say, on &lt;em&gt;this&lt;/em&gt; Thursday, it looks up for the file of &lt;em&gt;last&lt;/em&gt; Thursday...&lt;/p&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/excel-vba-open-files-with-variable.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-1102559480499560827</guid><pubDate>Sat, 30 Sep 2023 17:30:00 +0000</pubDate><atom:updated>2023-09-30T10:30:24.745-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Excel 2010</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba To Delete Multiple Rangenames For Single Range</title><description>&lt;div class="question"&gt;I have searched for an answer for hours, and can't search anymore.  Have Seen lots of discussions about deleting all range names from a workbook or a worksheet.  However, I need to&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;You are getting that error becuase you have not set &lt;code&gt;rgName&lt;/code&gt; after declaring it.&lt;/p&gt;&lt;p&gt;Here is my understanding of your question.&lt;/p&gt;&lt;p&gt;Lets say there is a Range &lt;code&gt;A1:A10&lt;/code&gt; in &lt;code&gt;Sheet1&lt;/code&gt; and Cell &lt;code&gt;A2&lt;/code&gt; has a name &lt;code&gt;NM1&lt;/code&gt; and Cell A5 has a name &lt;code&gt;NM2&lt;/code&gt; and cell D10 has a name &lt;code&gt;NM3&lt;/code&gt;&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;And you want a piece of code which deletes the Names in Range &lt;code&gt;A1:A10&lt;/code&gt; i.e &lt;code&gt;NM1&lt;/code&gt; and &lt;code&gt;NM2&lt;/code&gt; and not &lt;code&gt;NM3&lt;/code&gt;&lt;/p&gt;&lt;p&gt;If the above is what you want then try this&lt;/p&gt;&lt;pre&gt;&lt;code id="code_11" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Sample()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; rgName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, aCell &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Name

    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rgName = Sheets(&lt;span class="hljs-string"&gt;"Sheet1"&lt;/span&gt;).Range(&lt;span class="hljs-string"&gt;"A1:A10"&lt;/span&gt;)

    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ThisWorkbook.Names
        &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; aCell = Range(nName)
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-built_in"&gt;Not&lt;/span&gt; Intersect(aCell, rgName) &lt;span class="hljs-built_in"&gt;Is&lt;/span&gt;&lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; nName.Delete
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_11')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;And if I have misunderstood your question then you might want to rephrase it?&lt;/p&gt;&lt;p&gt;&lt;strong&gt;FOLLOWUP&lt;/strong&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;This has been an extremely useful site to me as a new VBA user, but I have ABSOLUTELY no idea how to add to this site, beyond these little notes. Please try to imagine the Name Manager in Excel 2010 - in Name Manager there are say 10 unique names, all for =Sheet1!$A$1. I want all of these names which pertain to Sheet1!$A$1 to be deleted by VBA code. I DO NOT want other names to be deleted anywhere. – LostInData 3 mins ago&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Based on your above comment try this&lt;/p&gt;&lt;pre&gt;&lt;code id="code_12" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Sample()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Name

    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ThisWorkbook.Names
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; nName.RefersTo = &lt;span class="hljs-string"&gt;"=Sheet1!$A$1"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; nName.Delete
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_12')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I think there is something missing in the solution given above.&lt;/p&gt;&lt;p&gt;In order to refer to the range of a named range with the range object you must use the name property of your named range. Therefore, not &lt;code&gt;Set aCell = Range(nName)&lt;/code&gt; but rather &lt;code&gt;Set aCell = Range(nName.Name)&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;Like this:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_15" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Sample()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; rgName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, aCell &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Name

    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rgName = Sheets(&lt;span class="hljs-string"&gt;"Sheet1"&lt;/span&gt;).Range(&lt;span class="hljs-string"&gt;"A1:A10"&lt;/span&gt;)

    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; nName &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ThisWorkbook.Names
        &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; aCell = Range(nName.Name)
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-built_in"&gt;Not&lt;/span&gt; Intersect(aCell, rgName) &lt;span class="hljs-built_in"&gt;Is&lt;/span&gt;&lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; nName.Delete
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_15')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-to-delete-multiple-rangenames-for.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-395039779605445692</guid><pubDate>Sat, 30 Sep 2023 16:47:00 +0000</pubDate><atom:updated>2023-09-30T09:47:05.687-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Check Whether Excel File Is Password Protected</title><description>&lt;div class="question"&gt;I am trying to open an Excel (xlsm) file via VBA. It may or may not be protected with a (known) password. I am using this code: On Error Resume Next Workbooks.Open filename, Passwo&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;For the record - the reason was indeed the structure protection of the workbook I was opening.
I could circumvent the problem by disabling structure protection, and re-protecting in Workbook_Open() (in the protected workbook). &lt;/p&gt;&lt;p&gt;With structure protection inactive, &lt;code&gt;Workbooks.Open&lt;/code&gt; with password does not fail even when there is no password.&lt;/p&gt;&lt;p&gt;Since I am opening via a VBA method, the VBA code is already trusted, meaning the Workbook_Open method will surely be called.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Use 1004 error handling exclusively for this particular problem, and On Error Resume Next for everything else in the Sub.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Above the statement &lt;code&gt;Workbooks.Open filename, Password:=user_entered_pw&lt;/code&gt;
also add another line statement without a password argument.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;If those (or their combination) don't work, try scouring the .xlsm flat code in Notepad for any hint that a PW protected file differs at that level from one without. Use that info in a pre-opening function.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/check-whether-excel-file-is-password.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-5996366709297627062</guid><pubDate>Sat, 30 Sep 2023 12:46:00 +0000</pubDate><atom:updated>2023-09-30T05:46:55.188-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Csv</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Python</category><title>How To Remove Newline Characters From Csv File</title><description>&lt;div class="question"&gt;I have the below part of code that reads values from the csv file 'prom output.csv' and writes them sorted in a new one 'sorted output.csv'. import collections import csv  with ope&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;apparently changing the line: &lt;code&gt;cr = csv.writer(f,lineterminator='\n')&lt;/code&gt;
into: &lt;code&gt;cr = csv.writer(f,sys.stdout, lineterminator='\n')&lt;/code&gt; and adding &lt;code&gt;import sys&lt;/code&gt; to the imports solves the problem.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Changing&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-ini"&gt;&lt;span class="hljs-attr"&gt;cr&lt;/span&gt; = csv.writer(f,delimiter=&lt;span class="hljs-string"&gt;","&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;to&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id="code_4" class="hljs language-ini"&gt;&lt;span class="hljs-attr"&gt;cr&lt;/span&gt; = csv.writer(f,delimiter=&lt;span class="hljs-string"&gt;","&lt;/span&gt;, lineterminator=&lt;span class="hljs-string"&gt;'\n'&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_4')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;does the trick.

I tried &lt;code&gt;cr = csv.writer(f, lineterminator='\n')&lt;/code&gt; and it still works.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;This is a simple feasible solution:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_6" class="hljs language-python"&gt;&lt;span class="hljs-keyword"&gt;import&lt;/span&gt; collections
&lt;span class="hljs-keyword"&gt;import&lt;/span&gt; csv

&lt;span class="hljs-keyword"&gt;with&lt;/span&gt;&lt;span class="hljs-built_in"&gt;open&lt;/span&gt;(&lt;span class="hljs-string"&gt;'prom output.csv'&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;as&lt;/span&gt; f:
    header = &lt;span class="hljs-built_in"&gt;next&lt;/span&gt;(csv.reader(f))
    d = collections.OrderedDict()
    &lt;span class="hljs-keyword"&gt;for&lt;/span&gt; r &lt;span class="hljs-keyword"&gt;in&lt;/span&gt; csv.reader(f):
        &lt;span class="hljs-keyword"&gt;try&lt;/span&gt;:
            d[r[&lt;span class="hljs-number"&gt;0&lt;/span&gt;]] += &lt;span class="hljs-string"&gt;','&lt;/span&gt;+r[&lt;span class="hljs-number"&gt;1&lt;/span&gt;]
        &lt;span class="hljs-keyword"&gt;except&lt;/span&gt;:
            d[r[&lt;span class="hljs-number"&gt;0&lt;/span&gt;]] = &lt;span class="hljs-string"&gt;','&lt;/span&gt;+r[&lt;span class="hljs-number"&gt;1&lt;/span&gt;]

&lt;span class="hljs-keyword"&gt;with&lt;/span&gt;&lt;span class="hljs-built_in"&gt;open&lt;/span&gt;(&lt;span class="hljs-string"&gt;'sorted output.csv'&lt;/span&gt;, &lt;span class="hljs-string"&gt;'w'&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;as&lt;/span&gt; f:
    cw = csv.writer(f)
    cw.writerow(header)
    &lt;span class="hljs-keyword"&gt;for&lt;/span&gt; k, v &lt;span class="hljs-keyword"&gt;in&lt;/span&gt; d.items():
        f.write(k+v+&lt;span class="hljs-string"&gt;'\n'&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_6')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;For the input of the following CSV file (&lt;code&gt;prom output.csv&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;case,event,startTime,completeTime
101,A
101,B
101,Y
102,C
102,D
102,U
103,A
103,B
103,Y
&lt;/pre&gt;&lt;p&gt;The output was (&lt;code&gt;sorted output.csv&lt;/code&gt;):&lt;/p&gt;&lt;pre&gt;case,event,startTime,completeTime
101,A,B,Y
102,C,D,U
103,A,B,Y

&lt;/pre&gt;&lt;p&gt;Which is the output as you intended it to be.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_4"&gt;Solution 4:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;The Python newline character is, '\n'. Therefore to remove the newline character (and hence the blank lines that are being printed) from your string, try:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_9" class="hljs language-bash"&gt;cr.writerow([k, (&lt;span class="hljs-string"&gt;","&lt;/span&gt;.&lt;span class="hljs-built_in"&gt;join&lt;/span&gt;(v)), .strip(&lt;span class="hljs-string"&gt;"\n"&lt;/span&gt;)])
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_9')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/how-to-remove-newline-characters-from.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-7953171328369019098</guid><pubDate>Sat, 30 Sep 2023 10:41:00 +0000</pubDate><atom:updated>2023-09-30T03:41:47.675-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Csv</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">R</category><category domain="http://www.blogger.com/atom/ns#">Xml</category><title>How To Read/convert Excel Xml Files To R/csv?</title><description>&lt;div class="question"&gt;I have few hundred XML files. They are probably generated from/to Excel. I would like to read it to R or convert to CSV. Headers of all files look like this: &lt;?xml version='1.0'&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;There is a chapter in the "R Data Import/Export" manual (one of the free manuals that installs with R) on reading data from Excel spreadsheets. If the above XML file is a saved spreadsheet from recent versions of Excel then some of those tools should read them easily. I would probably start with either the RODBC package or the XLConnect package.&lt;/p&gt;&lt;p&gt;If those don't work then the XML package should at least make writing the parser much easier.&lt;/p&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;</description><link>https://rrscils598f08.blogspot.com/2023/09/how-to-readconvert-excel-xml-files-to.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-1613681069522742538</guid><pubDate>Sat, 30 Sep 2023 07:44:00 +0000</pubDate><atom:updated>2023-09-30T00:44:43.664-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Powerquery</category><title>Complex Transformation In Excel Power Query</title><description>&lt;div class="question"&gt;I have 2 input Tables. Input Table1 is the source data and input Table 2 is a criteria table.  +--------------------------+----------+  +--------------------------+-------+ |&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Below is the UPDATED solution. &lt;/p&gt;&lt;p&gt;In general, I compiled the solution in order to be as less vulnerable to problems with data, as possible. &lt;/p&gt;&lt;p&gt;The only constrains to data are:&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;Field sets must have ID field, which must be the first field of set.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;all the RRUL and ADDR have to be in pairs,&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Duplicates of RRUL/ADDR pairs inside one ID are acceptable or absent.&lt;/p&gt;&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;I also compiled the solution in a way to correctly find the closest value in all possible variants of ADDR and PREFIX. By the way - there is one case, not covered in your bigsample - when PREFIX is shorter then ADDR but not equal to it. If there are such cases - my solution handles them correctly but demands some performance overhead for this particular situation.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-kotlin"&gt;let
        Source = #&lt;span class="hljs-string"&gt;"Source data"&lt;/span&gt;,
    #&lt;span class="hljs-string"&gt;"Added Index1"&lt;/span&gt; = Table.AddIndexColumn(Source, &lt;span class="hljs-string"&gt;"Index"&lt;/span&gt;, &lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;),

    #&lt;span class="hljs-string"&gt;"Added Custom"&lt;/span&gt; = Table.AddColumn(#&lt;span class="hljs-string"&gt;"Added Index1"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Main Key"&lt;/span&gt;, each &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; [DESCRIPTION] = &lt;span class="hljs-string"&gt;"ID"&lt;/span&gt; then [Index] &lt;span class="hljs-keyword"&gt;else&lt;/span&gt;&lt;span class="hljs-literal"&gt;null&lt;/span&gt;, type number),

    #&lt;span class="hljs-string"&gt;"Added Custom10"&lt;/span&gt; = Table.AddColumn(#&lt;span class="hljs-string"&gt;"Added Custom"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Last notADDR"&lt;/span&gt;, each 
        &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; [DESCRIPTION] &amp;lt;&amp;gt; &lt;span class="hljs-string"&gt;"ADDR"&lt;/span&gt; and [DESCRIPTION] &amp;lt;&amp;gt; &lt;span class="hljs-string"&gt;"RRUL"&lt;/span&gt; then [Index] &lt;span class="hljs-keyword"&gt;else&lt;/span&gt;&lt;span class="hljs-literal"&gt;null&lt;/span&gt;),

    #&lt;span class="hljs-string"&gt;"Filled Down"&lt;/span&gt; = Table.FillDown(#&lt;span class="hljs-string"&gt;"Added Custom10"&lt;/span&gt;,{&lt;span class="hljs-string"&gt;"Main Key"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Last notADDR"&lt;/span&gt;}),

    #&lt;span class="hljs-string"&gt;"Added Custom2"&lt;/span&gt; = Table.AddColumn(#&lt;span class="hljs-string"&gt;"Filled Down"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Key"&lt;/span&gt;, each [Main Key] + (
        &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; [DESCRIPTION] = &lt;span class="hljs-string"&gt;"RRUL"&lt;/span&gt; then [Index] - [Last notADDR] - &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-keyword"&gt;else&lt;/span&gt;&lt;span class="hljs-keyword"&gt;if&lt;/span&gt; [DESCRIPTION] = &lt;span class="hljs-string"&gt;"ADDR"&lt;/span&gt; then [Index] - [Last notADDR] - &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;else&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;)),

    #&lt;span class="hljs-string"&gt;"Removed Columns"&lt;/span&gt; = Table.RemoveColumns(#&lt;span class="hljs-string"&gt;"Added Custom2"&lt;/span&gt;,{&lt;span class="hljs-string"&gt;"Index"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Main Key"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"Last notADDR"&lt;/span&gt;}),

    #&lt;span class="hljs-string"&gt;"Pivoted Column1"&lt;/span&gt; = Table.Pivot(#&lt;span class="hljs-string"&gt;"Removed Columns"&lt;/span&gt;, 
        List.Distinct(#&lt;span class="hljs-string"&gt;"Removed Columns"&lt;/span&gt;[DESCRIPTION]), &lt;span class="hljs-string"&gt;"DESCRIPTION"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"VALUE"&lt;/span&gt;),

    #&lt;span class="hljs-string"&gt;"Added Custom3"&lt;/span&gt; = Table.AddColumn(#&lt;span class="hljs-string"&gt;"Pivoted Column1"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"CODE"&lt;/span&gt;, each &lt;span class="hljs-keyword"&gt;if&lt;/span&gt; [ADDR] = &lt;span class="hljs-literal"&gt;null&lt;/span&gt; then &lt;span class="hljs-literal"&gt;null&lt;/span&gt;&lt;span class="hljs-keyword"&gt;else&lt;/span&gt; let t = Table.AddIndexColumn(Table.SelectRows(Criterias, (x)=&amp;gt; 
        let s=List.Sort({x[PREFIX], [ADDR]}, each Text.Length(_)) &lt;span class="hljs-keyword"&gt;in&lt;/span&gt; Text.StartsWith(s{&lt;span class="hljs-number"&gt;1&lt;/span&gt;}, s{&lt;span class="hljs-number"&gt;0&lt;/span&gt;})), &lt;span class="hljs-string"&gt;"Index"&lt;/span&gt;)
            &lt;span class="hljs-keyword"&gt;in&lt;/span&gt;&lt;span class="hljs-keyword"&gt;if&lt;/span&gt; Table.RowCount(t) &amp;gt; &lt;span class="hljs-number"&gt;0&lt;/span&gt; then Table.First(Table.Sort(t, (y)=&amp;gt; Number.BitwiseShiftLeft(Number.Abs(Text.Length([ADDR]) - Text.Length(y[PREFIX])), &lt;span class="hljs-number"&gt;16&lt;/span&gt;) + y[Index]))[CODE] 
            &lt;span class="hljs-keyword"&gt;else&lt;/span&gt;&lt;span class="hljs-string"&gt;"Not Found"&lt;/span&gt;),
    #&lt;span class="hljs-string"&gt;"Removed Columns1"&lt;/span&gt; = Table.RemoveColumns(#&lt;span class="hljs-string"&gt;"Added Custom3"&lt;/span&gt;,{&lt;span class="hljs-string"&gt;"Key"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"ADDR"&lt;/span&gt;}),
    #&lt;span class="hljs-string"&gt;"Filled Down1"&lt;/span&gt; = Table.FillDown(#&lt;span class="hljs-string"&gt;"Removed Columns1"&lt;/span&gt;,{&lt;span class="hljs-string"&gt;"ID"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"NAME"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"TYPE"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"DFRUL"&lt;/span&gt;})
&lt;span class="hljs-keyword"&gt;in&lt;/span&gt;
    #&lt;span class="hljs-string"&gt;"Filled Down1"&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/complex-transformation-in-excel-power.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-4513145789666493037</guid><pubDate>Sat, 30 Sep 2023 05:27:00 +0000</pubDate><atom:updated>2023-09-29T22:27:27.787-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba Replace All In Column Within Sections Broken By "/"</title><description>&lt;div class="question"&gt;So I have some code that goes through a list of names (most are one username per row). A few of the row have multiple names broken up by the '/' character (John Doe / Smith Jr / So&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Try this: &lt;/p&gt;&lt;p&gt;&lt;code&gt;What:="/*Doe*/", Replacement:="/jdoe/"&lt;/code&gt;&lt;/p&gt;&lt;p&gt;And add a trailing &lt;code&gt;/&lt;/code&gt; to each cell in the range so it catches entries like &lt;code&gt;some name / john doe&lt;/code&gt;&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;This should also work, and doesn't require prefix/suffix anything. This processes 100K cells in about 6 seconds (per call to the &lt;code&gt;foo&lt;/code&gt; function). &lt;/p&gt;&lt;pre&gt;&lt;code id="code_4" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; main()
&lt;span class="hljs-comment"&gt;' This is your main procedure and you can specify all _&lt;/span&gt;&lt;span class="hljs-keyword"&gt;of&lt;/span&gt; your replacements here &lt;span class="hljs-keyword"&gt;on&lt;/span&gt; their own line:

&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; foo(&lt;span class="hljs-string"&gt;"*Doe*"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"jdoe"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; foo(&lt;span class="hljs-string"&gt;"*Ruth*"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"bruth"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; foo(&lt;span class="hljs-string"&gt;"*Washington*"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"gwashington"&lt;/span&gt;)
&lt;span class="hljs-comment"&gt;' etc...&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; foo(replace, replacement)
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; rng &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, cl &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, vals

&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; rng = Worksheets(&lt;span class="hljs-number"&gt;2&lt;/span&gt;).Range(&lt;span class="hljs-string"&gt;"B1:B100000"&lt;/span&gt;)  &lt;span class="hljs-comment"&gt;'Modify as needed&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cl &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; rng.Cells
    vals = Split(cl.Value, &lt;span class="hljs-string"&gt;" / "&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = LBound(vals) &lt;span class="hljs-keyword"&gt;To&lt;/span&gt; UBound(vals)
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; vals(i) &lt;span class="hljs-built_in"&gt;Like&lt;/span&gt; replace &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
            vals(i) = replacement
        &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;
    cl.Value = &lt;span class="hljs-keyword"&gt;Join&lt;/span&gt;(vals, &lt;span class="hljs-string"&gt;" / "&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_4')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-replace-all-in-column-within.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-1081283766439681135</guid><pubDate>Sat, 30 Sep 2023 01:42:00 +0000</pubDate><atom:updated>2023-09-29T18:42:38.119-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Collapsing Pivotfield With Duplicate Occurence /name</title><description>&lt;div class="question"&gt;I have a Pivot Table where I want to use the PivotField('Amount') two times. Once as a row and another as a value/datafield. The reason being is I have 'Total Amounts' for given mo&lt;/div&gt;

&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;
&lt;div class="answer-desc"&gt;&lt;p&gt;It works, try his code.&lt;/p&gt;
&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-comment"&gt;' doesn't works&lt;/span&gt;
PSheet.PivotTables(&lt;span class="hljs-string"&gt;"PivotTable"&lt;/span&gt;).PivotFields(&lt;span class="hljs-string"&gt;"Desc"&lt;/span&gt;).PivotItems.ShowDetail = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;

&lt;span class="hljs-comment"&gt;'works&lt;/span&gt;
PSheet.PivotTables(&lt;span class="hljs-string"&gt;"PivotTable"&lt;/span&gt;).PivotFields(&lt;span class="hljs-string"&gt;"Desc"&lt;/span&gt;).ShowDetail = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;

&lt;span class="hljs-comment"&gt;' works&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; pivotItm &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; PivotItem
 &lt;span class="hljs-keyword"&gt;For&lt;/span&gt; &lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; pivotItm &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; PSheet.PivotTables(&lt;span class="hljs-string"&gt;"PivotTable"&lt;/span&gt;).PivotFields(&lt;span class="hljs-string"&gt;"Desc"&lt;/span&gt;).PivotItems
  pivotItm.ShowDetail = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;
 &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt; pivotItm
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 
&lt;br&gt;
</description><link>https://rrscils598f08.blogspot.com/2023/09/collapsing-pivotfield-with-duplicate.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-3543543824958464036</guid><pubDate>Fri, 29 Sep 2023 22:53:00 +0000</pubDate><atom:updated>2023-09-29T15:53:36.632-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Office Interop</category><category domain="http://www.blogger.com/atom/ns#">Vb.net</category><title>Vb: Error Loading Type Library/dll. (exception From Hresult: 0x80029c4a (type_e_cantloadlibrary)</title><description>&lt;div class="question"&gt;I am working on an app which needs to import data from Excel. My solution is using Microsoft.office.Interop.Excel. But I get this error when I debug:  Message=Unable to cast COM ob&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;First of all, try to run Visual Studio with the &lt;code&gt;/ResetUserData&lt;/code&gt; command line argument. Read more about that in the &lt;a rel="nofollow noreferrer noopener" href="https://support.microsoft.com/en-us/help/968263/error-unable-to-cast-com-object-when-exporting-to-microsoft-excel-from"&gt;Error "Unable to cast COM object..." when exporting to Microsoft Excel from Team Explorer 2008&lt;/a&gt; article. &lt;/p&gt;&lt;p&gt;Obviously you are trying to connect to a wrong Excel version. Looks like you have some extra windows registry keys left after uninstalling an old version of Office or vice versa. Anyway, take a look at the &lt;a rel="nofollow noreferrer noopener" href="https://blogs.msdn.microsoft.com/dau-blog/2012/04/20/how-to-solve-unable-to-cast-com-object-of-type-microsoft-office-interop-excel-applicationclass-to-interface-type-microsoft-office-interop-excel-_application/"&gt;How to solve “Unable to cast COM object of type Microsoft.Office.Interop.Excel.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Excel._Application’”&lt;/a&gt; blog post which describes exactly the same issue. Basically you need to find a wrong entry in the windows registry and then delete it.&lt;/p&gt;&lt;p&gt;BTW When you add a new COM reference to the project a missed PIA is generated automatically (if it doesn't exist any longer). So, that is a possible way to go. Also you may try to embed interop types into your own assembly like the following screenshot shows: &lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/xy1t7.png"&gt;&lt;img alt="enter image description here" src="https://i.stack.imgur.com/xy1t7.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;If you set the &lt;code&gt;Embed Interop Types&lt;/code&gt; property to &lt;code&gt;True&lt;/code&gt; (since .NET Framework 4.0) and the &lt;code&gt;Specific Version&lt;/code&gt; property to &lt;code&gt;False&lt;/code&gt; for the Office Interop assembly reference, then your code should work with any version of Excel.&lt;/p&gt;&lt;p&gt;However, you must compile the code with the same bitness as your Office. For a 32-bit version of Office, you must compile your code as &lt;code&gt;x86&lt;/code&gt;, otherwise this exception can still occur on a 64-bit machine!&lt;/p&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/vb-error-loading-type-librarydll.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-7773881419786452027</guid><pubDate>Fri, 29 Sep 2023 20:49:00 +0000</pubDate><atom:updated>2023-09-29T13:49:33.719-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel 2007</category><category domain="http://www.blogger.com/atom/ns#">Sas</category><title>Using Libname Statement In 64 Bit Sas To Interact With 32 Excel</title><description>&lt;div class="question"&gt;I have 64 bit SAS 9.4 installed and 32 bit Office 2007.  When I had 32 bit SAS 9.3 installed, I was able to use a libname statement where the Excel file was the library and the 'fi&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;With SAS 9.4 or later 9.3 updates, you have another option: &lt;code&gt;dbms=XLSX&lt;/code&gt; or &lt;code&gt;dbms=XLS&lt;/code&gt;, both of which work regardless of bitness of office (As they're not using the JET engine or ACE engine). Still requre ACCESS to PC FILES, but they should work in mixed bitness systems.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;If you can install &lt;code&gt;SAS PC Files Server&lt;/code&gt;, you can still do this with the &lt;code&gt;PCFILES&lt;/code&gt; destination. Installing the PC Files Server software is out of the scope of an answer here, but google about for instructions, they are readily available. You can install the PC Files Server on your desktop, or on a central server if that's more convenient for your workplace.&lt;/p&gt;&lt;p&gt;Once you have it installed, you just access it by:&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id="code_4" class="hljs language-lua"&gt;libname mylib pcfiles &lt;span class="hljs-built_in"&gt;path&lt;/span&gt;=&lt;span class="hljs-string"&gt;"blah\blah\blah.xlsx"&lt;/span&gt;;
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_4')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Just like you did before, but with a different dbms type.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;The problem is you need the 64 bit Excel libraries for 64 bit SAS to interact with. &lt;/p&gt;&lt;p&gt;Chris Hemedinger posted a few work arounds to this issue as few years ago. &lt;a rel="nofollow noreferrer noopener" href="http://blogs.sas.com/content/sasdummy/2012/05/01/64-bit-gotchas/"&gt;http://blogs.sas.com/content/sasdummy/2012/05/01/64-bit-gotchas/&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you have ACCESS/ODBC, another option is to create an ODBC connection to the Excel spreadsheet. &lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/using-libname-statement-in-64-bit-sas.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-5661068550958600678</guid><pubDate>Fri, 29 Sep 2023 18:52:00 +0000</pubDate><atom:updated>2023-09-29T11:52:24.462-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Refer To Querytable Objects By Name</title><description>&lt;div class="question"&gt;I am developing a MS Excel 2013 tool with VBA, which involves the use of QueryTables. One inconvenience is accessing existing QueryTables within an Excel worksheet. Currently, the&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc" style="height: auto !important;"&gt;&lt;p&gt;In Excel 2003 and prior, an external data connection would create a QueryTable object whose parent was a worksheet. You could access the QueryTable object, for one, through the QueryTables collection object. Like most collection objects, you can pass an index number or a name to the (default) Item method to get it.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-bash"&gt;Sheet1.QueryTables(&lt;span class="hljs-string"&gt;"MyQtName"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;When you open a 2003 worksheet in a new version, it still has a QueryTable object and can be accessed the same way. Even if you convert the file format, the QueryTable persists.&lt;/p&gt;&lt;p&gt;In 2007 and later versions, there are only three ways to create a QueryTable that will be a member of Worksheet.QueryTables:&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;Through code&lt;/li&gt;&lt;li&gt;Data - From Text&lt;/li&gt;&lt;li&gt;Data - From Web&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;All other UI external data connections in these new versions will result not in a QueryTables member, but in a ListObject. That ListObject will have one and only one QueryTable object that can be accessed via the ListObject.QueryTable property.&lt;/p&gt;&lt;p&gt;Here's the bad news. The QueryTable whose parent in a ListObject doesn't have a Name property. Well, it's there, but you will get a runtime error 1004 if you try to access it. I guess MS decided since there's only one QueryTable per ListObject, it didn't make sense that it should have a name.&lt;/p&gt;&lt;p&gt;If you try to convert a Worksheet.QueryTables.QueryTable into a ListObject, the external data connection goes away and the new ListObject doesn't have a QueryTable.&lt;/p&gt;&lt;p&gt;Since your QueryTables.Count is returning zero, all of your QueryTables are inside ListObjects and don't have names. The ListObjects have names. You can use&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-bash"&gt;Sheet1.ListObjects(&lt;span class="hljs-string"&gt;"MyListName"&lt;/span&gt;).QueryTable
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Here's a function that takes a name and a worksheet and returns a QueryTable that either has that name or is a child of a ListObject that has that name.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_2" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Public&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt; QueryTableByName(&lt;span class="hljs-keyword"&gt;ByVal&lt;/span&gt; sName &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;, &lt;span class="hljs-keyword"&gt;ByRef&lt;/span&gt; sh &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet) &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; QueryTable

    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; qt &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; QueryTable
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lo &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; ListObject

    &lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Resume&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; qt = sh.QueryTables(sName)
    &lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;GoTo&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt; qt &lt;span class="hljs-built_in"&gt;Is&lt;/span&gt;&lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Resume&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; lo = sh.ListObjects(sName)
        &lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;GoTo&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-built_in"&gt;Not&lt;/span&gt; lo &lt;span class="hljs-built_in"&gt;Is&lt;/span&gt;&lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Resume&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; qt = lo.QueryTable
            &lt;span class="hljs-keyword"&gt;On&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Error&lt;/span&gt;&lt;span class="hljs-keyword"&gt;GoTo&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; QueryTableByName = qt

&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_2')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;According to &lt;a rel="nofollow noreferrer noopener" href="https://msdn.microsoft.com/en-us/library/ff841237%28v=office.14%29.aspx"&gt;this MSDN link for ListObject&lt;/a&gt; there isn't any collection of &lt;code&gt;QueryTables&lt;/code&gt; being a property of &lt;code&gt;ListObjects&lt;/code&gt;. Correct code is:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_5" class="hljs language-java"&gt;&lt;span class="hljs-type"&gt;Set&lt;/span&gt;&lt;span class="hljs-variable"&gt;QT&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; querySheet.ListObjects.items(&lt;span class="hljs-number"&gt;1&lt;/span&gt;).QueryTable
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_5')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;What you possibly need is to refer to appropriate &lt;code&gt;ListObject item&lt;/code&gt; like (just example code):&lt;/p&gt;&lt;pre&gt;&lt;code id="code_7" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; LS &lt;span class="hljs-keyword"&gt;as&lt;/span&gt; ListObject
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; LS = querySheet.ListObjects(&lt;span class="hljs-string"&gt;"My LO 1"&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; QT = LS.QueryTable
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_7')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The other alternative is to refer to QT through &lt;code&gt;WorkSheet property&lt;/code&gt; in this way:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_9" class="hljs language-java"&gt;&lt;span class="hljs-type"&gt;Set&lt;/span&gt;&lt;span class="hljs-variable"&gt;QT&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; Worksheet(&lt;span class="hljs-string"&gt;"QTable"&lt;/span&gt;).QueryTables(&lt;span class="hljs-string"&gt;"My Query Table"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_9')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;This works:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_10" class="hljs language-sql"&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;("ClassifiedAsSupply").ListObject.QueryTable.Refresh BackgroundQuery:&lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-literal"&gt;True&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_10')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Thanks to Dingbatdata: &lt;a rel="nofollow noreferrer noopener" href="https://www.dingbatdata.com/2017/11/24/referencing-listobjects-with-vba/#comment-719"&gt;https://www.dingbatdata.com/2017/11/24/referencing-listobjects-with-vba/#comment-719&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/refer-to-querytable-objects-by-name.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8145648608490984084</guid><pubDate>Fri, 29 Sep 2023 17:56:00 +0000</pubDate><atom:updated>2023-09-29T10:56:04.186-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Decimal</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Numbers</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Excel Print Number With Correct Decimal Seperator</title><description>&lt;div class="question"&gt;I use the print function to export a Cell Value to csv file. I use this macro on several PCs with different Localization Settings. The problem i am experiencing is, that on some PC&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;As far as I'm aware, there is no format method for changing the decimal separator. Instead your options are temporarily telling Excel to use a special character or using Replace().&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-php"&gt;Application.UseSystemSeparators = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;
Application.DecimalSeparator = &lt;span class="hljs-string"&gt;";"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Print&lt;/span&gt;&lt;span class="hljs-comment"&gt;#1, rngValue.Text&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Or&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-less"&gt;&lt;span class="hljs-selector-tag"&gt;Print&lt;/span&gt;&lt;span class="hljs-selector-id"&gt;#1&lt;/span&gt;, &lt;span class="hljs-selector-tag"&gt;Replace&lt;/span&gt;(rngValue, &lt;span class="hljs-string"&gt;","&lt;/span&gt;, &lt;span class="hljs-string"&gt;";"&lt;/span&gt;) 
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;In either case you then have a problem, when reading the numbers back in, of converting them back to the correct character so they are considered numbers.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;A better question might be how do programmers in places that use the comma as the decimal separator handle decimal values in CSV files?&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/excel-print-number-with-correct-decimal.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-6636264896664505775</guid><pubDate>Fri, 29 Sep 2023 16:46:00 +0000</pubDate><atom:updated>2023-09-29T09:46:56.838-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Powerpoint</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Activex Can't Create Object Powerpont Vba</title><description>&lt;div class="question"&gt;I am trying to copy 1st slide from the powerpoint and insert it at the end but I am getting ActiveX can't create object on the line ActivePresentation.Slides(1).Copy  This is my fu&lt;/div&gt;

&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;
&lt;div class="answer-desc"&gt;&lt;p&gt;Try edited code below, I have &lt;code&gt;ppApp As PowerPoint.Application&lt;/code&gt; and &lt;code&gt;Dim ppPres As PowerPoint.Presentation&lt;/code&gt; :&lt;/p&gt;
&lt;pre&gt;&lt;code id="code_2" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt; &lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;

&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; myFile, Fileselected &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; &lt;span class="hljs-type"&gt;String&lt;/span&gt;, Path &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; &lt;span class="hljs-type"&gt;String&lt;/span&gt;, objPPT &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; &lt;span class="hljs-type"&gt;Object&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; ppApp   &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; PowerPoint.Application
&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; ppPres  &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; PowerPoint.Presentation

&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; activeSlide &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; PowerPoint.Slide

&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Generate_PPTs()

Application.ScreenUpdating = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;

&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; myFile = Application.FileDialog(msoFileDialogOpen)
&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; myFile
    .Title = &lt;span class="hljs-string"&gt;"Choose Template PPT File."&lt;/span&gt;
    .AllowMultiSelect = &lt;span class="hljs-literal"&gt;False&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;If&lt;/span&gt; .Show &amp;lt;&amp;gt; -&lt;span class="hljs-number"&gt;1&lt;/span&gt; &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
    &lt;span class="hljs-keyword"&gt;Exit&lt;/span&gt; &lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt; &lt;span class="hljs-keyword"&gt;If&lt;/span&gt;
    Fileselected = .SelectedItems(&lt;span class="hljs-number"&gt;1&lt;/span&gt;)
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt; &lt;span class="hljs-keyword"&gt;With&lt;/span&gt;
Path = Fileselected

&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; i &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; &lt;span class="hljs-type"&gt;Integer&lt;/span&gt;

&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; ppApp = &lt;span class="hljs-built_in"&gt;New&lt;/span&gt; PowerPoint.Application
i = &lt;span class="hljs-number"&gt;1&lt;/span&gt;

ppApp.Presentations.Open Filename:=Path  &lt;span class="hljs-comment"&gt;' 'PowerPointFile = "C:\Test.pptx"&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; ppPres = ppApp.Presentations.Item(i)

&lt;span class="hljs-comment"&gt;' for debug&lt;/span&gt;
Debug.Print ppPres.Name

ppPres.Slides(&lt;span class="hljs-number"&gt;1&lt;/span&gt;).Copy
ppPres.Slides.Paste Index:=ppPres.Slides.Count + &lt;span class="hljs-number"&gt;1&lt;/span&gt;

&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; activeSlide = ppPres.Slides(ppPres.Slides.Count)

Application.ScreenUpdating = &lt;span class="hljs-literal"&gt;True&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; ppPres = &lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;
&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; ppApp = &lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;

&lt;span class="hljs-keyword"&gt;End&lt;/span&gt; &lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_2')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 
&lt;br&gt;
</description><link>https://rrscils598f08.blogspot.com/2023/09/activex-cant-create-object-powerpont-vba.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-5375361649591300123</guid><pubDate>Fri, 29 Sep 2023 13:41:00 +0000</pubDate><atom:updated>2023-09-29T06:41:53.923-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Parsing</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><category domain="http://www.blogger.com/atom/ns#">Web Scraping</category><category domain="http://www.blogger.com/atom/ns#">Xmlhttprequest</category><title>Xml Web Scraping A Website With Dynamic Key</title><description>&lt;div class="question"&gt;I have been scraping this site from Excel using IE but recently using IE has been inconsistent and slow. My list is usually around 500 to 1000 so I have to run the macro over night&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I've submitted the same search request from the web form on the webpage in Firefox. After that I opened Developer Tools &lt;kbd&gt;F12&lt;/kbd&gt;, Network tab, clicked last POST request, opened Parameters section, and here is a screenshot of the parameters that have been submitted:&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/FvoXT.png"&gt;&lt;img alt="form data" src="https://i.stack.imgur.com/FvoXT.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Raw Form Data:&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;blockquote&gt;&lt;p&gt;__EVENTTARGET=&amp;amp;__EVENTARGUMENT=&amp;amp;__VIEWSTATE=%2FwEPDwULLTEyNDQ4MDU4OTkPZBYCZg9kFgICAw9kFgICDQ9kFgYCAQ9kFgICAw9kFgICAQ8QZBAVARUxNzAwIFNQUklORyBHQVJERU4gU1QVARUxNzAwIFNQUklORyBHQVJERU4gU1QUKwMBZxYBZmQCBQ8PFgIeBFRleHQFHFBsZWFzZSBhZGQgYWRkcmVzcyB0byBsb29rdXBkZAINDw8WAh4HVmlzaWJsZWhkFgoCAQ88KwAKAQAPFgQeC18hRGF0YUJvdW5kZx4LXyFJdGVtQ291bnRmZGQCAw9kFgICBQ8PFgIeF0VuYWJsZUFqYXhTa2luUmVuZGVyaW5naGRkAgUPFCsAAg8WAh8EaGQQFgJmAgEWAg8WBB4LTmF2aWdhdGVVcmwFJC4uL0ZlZWRiYWNrRm9ybS5hc3B4P0JydE5vPTc3MjUzNDcwMB8EaGQPFgQfBQUdfi9QREZzL1BheW1lbnRfQWdyZWVtZW50cy5wZGYfBGhkDxYCZmYWAQVxVGVsZXJpay5XZWIuVUkuUmFkV2luZG93LCBUZWxlcmlrLldlYi5VSSwgVmVyc2lvbj0yMDEwLjEuNTE5LjQwLCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPTEyMWZhZTc4MTY1YmEzZDQWBGYPDxYEHwUFJC4uL0ZlZWRiYWNrRm9ybS5hc3B4P0JydE5vPTc3MjUzNDcwMB8EaGRkAgEPDxYEHwUFHX4vUERGcy9QYXltZW50X0FncmVlbWVudHMucGRmHwRoZGQCBw88KwARAgAPFgQfAmcfA2ZkARAWABYAFgBkAgkPFgIeBXZhbHVlBQk3NzI1MzQ3MDBkGAIFQWN0bDAwJEJvZHlDb250ZW50UGxhY2VIb2xkZXIkR2V0VGF4SW5mb0NvbnRyb2wkZ3JkUGF5bWVudHNIaXN0b3J5DzwrAAwBCGZkBTJjdGwwMCRCb2R5Q29udGVudFBsYWNlSG9sZGVyJEdldFRheEluZm9Db250cm9sJGZybQ9nZD9K5t7genscvOsiNrdPkxL0VHWCYSsS%2FK3EZTRu3h3w&amp;amp;__EVENTVALIDATION=%2FwEWBQKkrNCPCgLRzsWTBwLlpIbACAKV6q2KDQKIvdHyCawQaHbBYSHV%2B%2FVvyLUTUY%2BhSsmbpTvj0W4ycfOa1RCO&amp;amp;ctl00%24BodyContentPlaceHolder%24SearchByAddressControl%24txtLookup=by+Property+Address&amp;amp;ctl00%24BodyContentPlaceHolder%24SearchByBRTControl%24txtTaxInfo=043185500&amp;amp;ctl00%24BodyContentPlaceHolder%24SearchByBRTControl%24btnTaxByBRT=+%3E%3E&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Note that there are 7 parameters. All of them should be URL-encoded. I've slightly reworked and modified your code, also added some request headers. The following code works correct for me:&lt;/p&gt;&lt;pre class="lang-vb prettyprint-override"&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; test_66()

    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; s1 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; s2 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; sResp &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; aTmp &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Variant
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; sBRTNumber &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; sFormData &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; CreateObject(&lt;span class="hljs-string"&gt;"MSXML2.XMLHTTP"&lt;/span&gt;)
        .Open &lt;span class="hljs-string"&gt;"GET"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"http://www.phila.gov/revenue/realestatetax/default.aspx"&lt;/span&gt;, &lt;span class="hljs-literal"&gt;False&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"text/html;charset=UTF-8"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept-Encoding"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"identity"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept-Charset"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"UTF-8"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Connection"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"keep-alive"&lt;/span&gt;
        .send
        sResp = .responseText
    &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;
    aTmp = Split(sResp, &lt;span class="hljs-string"&gt;"id=""__VIEWSTATE"" value="""&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;)
    s1 = aTmp(&lt;span class="hljs-number"&gt;1&lt;/span&gt;)
    aTmp = Split(s1, &lt;span class="hljs-string"&gt;""""&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;)
    s1 = aTmp(&lt;span class="hljs-number"&gt;0&lt;/span&gt;)
    aTmp = Split(sResp, &lt;span class="hljs-string"&gt;"id=""__EVENTVALIDATION"" value="""&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;)
    s2 = aTmp(&lt;span class="hljs-number"&gt;1&lt;/span&gt;)
    aTmp = Split(s2, &lt;span class="hljs-string"&gt;""""&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;)
    s2 = aTmp(&lt;span class="hljs-number"&gt;0&lt;/span&gt;)
    s1 = EncodeUriComponent(s1)
    s2 = EncodeUriComponent(s2)

    sBRTNumber = &lt;span class="hljs-string"&gt;"043185500"&lt;/span&gt;
    sFormData = &lt;span class="hljs-keyword"&gt;Join&lt;/span&gt;(Array( _
        &lt;span class="hljs-string"&gt;"__EVENTTARGET="&lt;/span&gt;, _
        &lt;span class="hljs-string"&gt;"__EVENTARGUMENT="&lt;/span&gt;, _
        &lt;span class="hljs-string"&gt;"__VIEWSTATE="&lt;/span&gt; &amp;amp; s1, _
        &lt;span class="hljs-string"&gt;"__EVENTVALIDATION="&lt;/span&gt; &amp;amp; s2, _
        &lt;span class="hljs-string"&gt;"ctl00%24BodyContentPlaceHolder%24SearchByAddressControl%24txtLookup=by+Property+Address"&lt;/span&gt;, _
        &lt;span class="hljs-string"&gt;"ctl00%24BodyContentPlaceHolder%24SearchByBRTControl%24txtTaxInfo="&lt;/span&gt; &amp;amp; sBRTNumber, _
        &lt;span class="hljs-string"&gt;"ctl00%24BodyContentPlaceHolder%24SearchByBRTControl%24btnTaxByBRT=+%3E%3E"&lt;/span&gt; _
        ), &lt;span class="hljs-string"&gt;"&amp;amp;"&lt;/span&gt;)

    &lt;span class="hljs-keyword"&gt;With&lt;/span&gt; CreateObject(&lt;span class="hljs-string"&gt;"MSXML2.XMLHTTP"&lt;/span&gt;)
        .Open &lt;span class="hljs-string"&gt;"POST"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"http://www.phila.gov/revenue/realestatetax/default.aspx"&lt;/span&gt;, &lt;span class="hljs-literal"&gt;False&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Content-Type"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"application/x-www-form-urlencoded"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"text/html;charset=UTF-8"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept-Encoding"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"identity"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Accept-Charset"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"UTF-8"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Connection"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"keep-alive"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Host"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"www.phila.gov"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Origin"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"http://www.phila.gov"&lt;/span&gt;
        .setRequestHeader &lt;span class="hljs-string"&gt;"Referer"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"http://www.phila.gov/revenue/realestatetax/default.aspx"&lt;/span&gt;
        .send (sFormData)
        sResp = .responseText
    &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; CreateObject(&lt;span class="hljs-string"&gt;"InternetExplorer.Application"&lt;/span&gt;)
        .navigate &lt;span class="hljs-string"&gt;"about:blank"&lt;/span&gt;
        .Visible = &lt;span class="hljs-literal"&gt;True&lt;/span&gt;
        .document.write sResp
    &lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt; EncodeUriComponent(strText &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;) &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Static&lt;/span&gt; objHtmlfile &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Object&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt; objHtmlfile &lt;span class="hljs-built_in"&gt;Is&lt;/span&gt;&lt;span class="hljs-literal"&gt;Nothing&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; objHtmlfile = CreateObject(&lt;span class="hljs-string"&gt;"htmlfile"&lt;/span&gt;)
        objHtmlfile.parentWindow.execScript &lt;span class="hljs-string"&gt;"function encode(s) {return encodeURIComponent(s)}"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"jscript"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;
    EncodeUriComponent = objHtmlfile.parentWindow.encode(strText)
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;And here is the IE window output:&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/VyVLp.png"&gt;&lt;img alt="output" src="https://i.stack.imgur.com/VyVLp.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/xml-web-scraping-website-with-dynamic.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-3011454735689820577</guid><pubDate>Fri, 29 Sep 2023 11:48:00 +0000</pubDate><atom:updated>2023-09-29T04:48:43.201-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Arrays</category><category domain="http://www.blogger.com/atom/ns#">Countif</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Excel Formula</category><title>Countif The Result Of Subtracting Two Arrays Exceeds A Certain Value In Excel</title><description>&lt;div class="question"&gt;I am new to array formulae and am having trouble with the following scenario: I have the following matrix: F   G   H   I   J  ...  R   S   T   U   V 1   0   0   1   1&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;As an array formula in one cell without volatile functions:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-sql"&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-built_in"&gt;SUM&lt;/span&gt;((MMULT(&lt;span class="hljs-comment"&gt;--(LEN(F2:J5)*LEN(R2:V5)&amp;gt;0),--TRANSPOSE(COLUMN(F2:J2)&amp;gt;0))=5)*(MMULT(F2:J5-R2:V5,TRANSPOSE(--(COLUMN(F2:J2)&amp;gt;0)))&amp;gt;2.5))&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;should do the trick :D&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Maybe, in say X1 (assuming you have labelled your columns):&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-makefile"&gt;&lt;span class="hljs-section"&gt;=COUNTIF(Y:Y,TRUE)&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;In Y1 whatever your chosen cutoff (eg &lt;code&gt;2.5&lt;/code&gt;) and in Y2:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-sql"&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt;((COUNTBLANK(F2:J2)&lt;span class="hljs-operator"&gt;+&lt;/span&gt;COUNTBLANK(R2:V2)&lt;span class="hljs-operator"&gt;=&lt;/span&gt;&lt;span class="hljs-number"&gt;0&lt;/span&gt;)&lt;span class="hljs-operator"&gt;*&lt;/span&gt;&lt;span class="hljs-built_in"&gt;SUM&lt;/span&gt;(F2:J2)&lt;span class="hljs-operator"&gt;-&lt;/span&gt;&lt;span class="hljs-built_in"&gt;SUM&lt;/span&gt;(R2:V2))&lt;span class="hljs-operator"&gt;&amp;gt;&lt;/span&gt;Y$&lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;copied down to suit.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Try this:&lt;/p&gt;&lt;p&gt;&lt;code&gt;=SUMPRODUCT((MMULT(F1:J4-R1:V4,--(ROW(INDIRECT("1:"&amp;amp;COLUMNS(F1:J4)))&amp;gt;0))&amp;gt;2.5)*(MMULT((LEN(F1:J4)&amp;gt;0)+(LEN(R1:V4)&amp;gt;0),--(ROW(INDIRECT("1:"&amp;amp;COLUMNS(F1:J4)))&amp;gt;0))=(COLUMNS(F1:J4)+COLUMNS(R1:V4))))&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/TGyjE.png"&gt;&lt;img alt="enter image description here" src="https://i.stack.imgur.com/TGyjE.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_4"&gt;Solution 4:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I think this will do it, replacing your AND's by multiplies (*):&lt;/p&gt;&lt;pre&gt;&lt;code id="code_5" class="hljs language-lua"&gt;=SUMPRODUCT(&lt;span class="hljs-comment"&gt;--((SUBTOTAL(9,OFFSET(F1,ROW(F1:F4)-ROW(F1),0,1,COLUMNS(F1:J1)))-SUBTOTAL(9,OFFSET(R1,ROW(R1:R4)-ROW(R1),0,1,COLUMNS(R1:V1)))&amp;gt;2.5)*(SUBTOTAL(2,OFFSET(F1,ROW(F1:F4)-ROW(F1),0,1,COLUMNS(F1:J1)))=COLUMNS(F1:J1))*(SUBTOTAL(2,OFFSET(R1,ROW(R1:R4)-ROW(R1),0,1,COLUMNS(R1:V1)))=COLUMNS(R1:V1))&amp;gt;0))&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_5')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;It could be simplified a bit more but a bit short of time.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_5"&gt;Solution 5:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Just another option... &lt;/p&gt;&lt;p&gt;&lt;code&gt;=IF(NOT(OR(IFERROR(MATCH(TRUE,ISBLANK(F1:J1),0),FALSE),IFERROR(MATCH(TRUE,ISBLANK(R1:V1),0),FALSE))), SUBTOTAL(9,F1:J1)-SUBTOTAL(9,R1:V1), "Missing Value(s)")&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;a rel="nofollow noreferrer noopener" href="https://i.stack.imgur.com/Ys7TH.png"&gt;&lt;img alt="![![![My results" src="https://i.stack.imgur.com/Ys7TH.png"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;My approach was a little different from what you tried to adapt from @TomSharp in that I'm validating the cells have data (not blank) and then perform the calculation, othewise return an error message. This is still an array function call, so when you enter the formulas, press &lt;code&gt;ctrl+shft+enter&lt;/code&gt;.&lt;/p&gt;&lt;p&gt;The condition part of the opening &lt;code&gt;if()&lt;/code&gt; checks to see that each range's cells are not blank: &lt;code&gt;if a match( true= isblank(cell))&lt;/code&gt;
means a cell is blank (bad), if no match ... ie no blank cells, Match will return an #NA "error" (good). False is good = Errors found ? No. ((ie no blank cells))&lt;/p&gt;&lt;p&gt;Then the threshold condition becomes: &lt;/p&gt;&lt;p&gt;&lt;code&gt;=COUNTIF(X1:X4,"&amp;gt;"&amp;amp;Threshold)' Note: no Array formula here&lt;/code&gt;&lt;/p&gt;&lt;p&gt;I gave the threshold (Cell &lt;code&gt;W6&lt;/code&gt;) a named range for read ablity. &lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/countif-result-of-subtracting-two.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-7895983239382895615</guid><pubDate>Fri, 29 Sep 2023 10:47:00 +0000</pubDate><atom:updated>2023-09-29T03:47:07.185-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba: Loop Through Rows, Sum Up Certain Rows If Condition Is Met</title><description>&lt;div class="question"&gt;I have been using the forums for a couple of weeks now while learning VBA. But now I am stuck and need help. So here is my problem: I have a workbook with several worksheets in it.&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;You're close, but you need to test each cell individually inside your loop. Something like this:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Macro1()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; tbl &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Worksheet
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; x &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lrow &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; lastname &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; astatus &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; number &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; counter &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;: counter = &lt;span class="hljs-number"&gt;3&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; wb = ThisWorkbook
    &lt;span class="hljs-keyword"&gt;Set&lt;/span&gt; tbl = wb.Sheets(&lt;span class="hljs-string"&gt;"Sheet1"&lt;/span&gt;)
    lrow = tbl.Cells(Rows.Count, &lt;span class="hljs-string"&gt;"B"&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;(xlUp).Row

    &lt;span class="hljs-keyword"&gt;For&lt;/span&gt; x = &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; lrow
        &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; tbl.Range(&lt;span class="hljs-string"&gt;"C"&lt;/span&gt; &amp;amp; x) = &lt;span class="hljs-string"&gt;"Smith"&lt;/span&gt;&lt;span class="hljs-built_in"&gt;And&lt;/span&gt; tbl.Range(&lt;span class="hljs-string"&gt;"E"&lt;/span&gt; &amp;amp; x) = &lt;span class="hljs-string"&gt;"Talking"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
            Range(&lt;span class="hljs-string"&gt;"I"&lt;/span&gt; &amp;amp; counter).Value = Range(&lt;span class="hljs-string"&gt;"C"&lt;/span&gt; &amp;amp; x)
            Range(&lt;span class="hljs-string"&gt;"J"&lt;/span&gt; &amp;amp; counter).Value = Range(&lt;span class="hljs-string"&gt;"E"&lt;/span&gt; &amp;amp; x)
            Range(&lt;span class="hljs-string"&gt;"K"&lt;/span&gt; &amp;amp; counter).Value = Range(&lt;span class="hljs-string"&gt;"H"&lt;/span&gt; &amp;amp; x)
            counter = counter + &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;If&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt; x
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;hr&gt;&lt;p&gt;Per @Tim comment you can use SumIfs to return the total of 'H' column that meet multiple criteria like this:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-bash"&gt;=SUMIFS(H:H,C:C,&lt;span class="hljs-string"&gt;"=Smith"&lt;/span&gt;,E:E,&lt;span class="hljs-string"&gt;"=Talking"&lt;/span&gt;)
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;I found a way that does the job for me so far, but this seems pretty messed up since I have to do it for every case manually. So now I am looking for a simpler and more elegant way to do this. If you could provide me with some code or point me into the right direction, I would highly appreciate it.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;Here is my code so far:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_2" class="hljs language-sql"&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cell &lt;span class="hljs-keyword"&gt;In&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;("H2:H" &lt;span class="hljs-operator"&gt;&amp;amp;&lt;/span&gt; lrow)
   cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; cell.Value &lt;span class="hljs-operator"&gt;+&lt;/span&gt; cell.Offset(&lt;span class="hljs-number"&gt;-1&lt;/span&gt;, &lt;span class="hljs-number"&gt;1&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;
      If cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-6&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Smith" &lt;span class="hljs-keyword"&gt;And&lt;/span&gt; cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-3&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Talking" &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
      cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;2&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; cell.Value
      &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If

      If cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-6&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Smith" &lt;span class="hljs-keyword"&gt;And&lt;/span&gt; cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-3&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Ready" &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
         cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;3&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; cell.Value
      &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If

      If cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-6&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Smith" &lt;span class="hljs-keyword"&gt;And&lt;/span&gt; cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;-3&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; "Not Ready" &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
      cell.Offset(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;4&lt;/span&gt;).&lt;span class="hljs-keyword"&gt;Value&lt;/span&gt;&lt;span class="hljs-operator"&gt;=&lt;/span&gt; cell.Value
      &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If
Next
&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_2')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;As mentioned before, it is a workaround which I would like have to be simplified. It looks for the condition "Smith" and the status "Talking", "Ready" and "Not Ready" and puts the value of the H Column into the respective cells of the columns to it's right to be summed in the later process. So, is there any way to make that more elegant?&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_3"&gt;Solution 3:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Sure thing Portland Runner! My logic is simple. I've got list of recorded activities for each name with certain statusses. e.g. "Smith" (column B) and "Talking" (column C) and a number (column H). And I need to sum up the numbers in column H for every row where the conditions name and status are equal. Let's say I have 10k rows. 2k of them have the name "Smith" in it. But only 500 of them have the name "Smith" and the status "Talking". So I need to figure out a simpler way to sum up those numbers. There are also rows where the name is "Smith" but the status is "Ready". The difficulty here is, that those lines are basically in a random order.&lt;/p&gt;&lt;p&gt;So the table would look like this:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_3" class="hljs language-javascript"&gt;&lt;span class="hljs-title class_"&gt;Row&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Name&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Status&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Number&lt;/span&gt;&lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Smith&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Talking&lt;/span&gt;&lt;span class="hljs-number"&gt;105&lt;/span&gt;&lt;span class="hljs-number"&gt;3&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Smith&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Talking&lt;/span&gt;&lt;span class="hljs-number"&gt;67&lt;/span&gt;&lt;span class="hljs-number"&gt;4&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Smith&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Ready&lt;/span&gt;&lt;span class="hljs-number"&gt;75&lt;/span&gt;&lt;span class="hljs-number"&gt;5&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Smith&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Talking&lt;/span&gt;&lt;span class="hljs-number"&gt;94&lt;/span&gt;&lt;span class="hljs-number"&gt;6&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Jones&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Ready&lt;/span&gt;&lt;span class="hljs-number"&gt;89&lt;/span&gt;&lt;span class="hljs-number"&gt;7&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Jones&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Talking&lt;/span&gt;&lt;span class="hljs-number"&gt;224&lt;/span&gt;&lt;span class="hljs-number"&gt;8&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Jones&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Not&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Ready&lt;/span&gt;&lt;span class="hljs-number"&gt;75&lt;/span&gt;&lt;span class="hljs-number"&gt;9&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Jones&lt;/span&gt;&lt;span class="hljs-title class_"&gt;Talking&lt;/span&gt;&lt;span class="hljs-number"&gt;99&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_3')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;So in this case row number 1 would be blocked for the headline and the data would start in row number 2. For "Smith" and "Talking" the code would need to sum the numbers of rows 2,3 and 5 for the condition "Smith" and "Talking". Rows 4 for "Smith" and "Ready". Rows 7 and 9 for "Jones" and "Talking" and so on. &lt;/p&gt;&lt;p&gt;What I can do, is create a new worksheet and put a list of all names in column A and a list of all statusses into column B and reference to it. That would save me the trouble of using the exact names and statusses in the code, but wouldn't solve my problem.&lt;/p&gt;&lt;/div&gt;&lt;h2 id="solution_4"&gt;Solution 4:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;A. Get all unique Name and place in a new column: this will be your array used to search each row.&lt;/p&gt;&lt;p&gt;B. Set up another array for Status since you know what the status could be.&lt;/p&gt;&lt;p&gt;C. Set up outer loop for Name Array
For each item in array &lt;/p&gt;&lt;p&gt;D. Nested loop look at each row and search on each status&lt;/p&gt;&lt;p&gt;C. When status matches then another nested loop to add time and place in a new column called total time.&lt;/p&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-loop-through-rows-sum-up-certain.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8195207198836938781</guid><pubDate>Fri, 29 Sep 2023 09:49:00 +0000</pubDate><atom:updated>2023-09-29T02:49:16.044-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Ms Access</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Array Prepared Within A Vba Event. How To Extract Its Contents From Inside A Different Event?</title><description>&lt;div class="question"&gt;This question should apply to any VBA situ with events: I've filled an array within a Form_Load() event in MS Access.  Now I would like to extract, dereference, the contents of tha&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;Let's start with a simple single Dimension example. Tested in access 2010.&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Compare&lt;/span&gt; Database
&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; singleArray() &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-comment"&gt;'start with one element&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; currentLength &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-comment"&gt;'variable to keep track of number of elements&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Private&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Command0_Click()
    Debug.Print &lt;span class="hljs-string"&gt;"Accessed from Event "&lt;/span&gt; &amp;amp; singleArray(&lt;span class="hljs-number"&gt;0&lt;/span&gt;) &lt;span class="hljs-comment"&gt;'access from event&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PrintArray &lt;span class="hljs-comment"&gt;'calling function to print array&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Private&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Form_Load()

    &lt;span class="hljs-comment"&gt;'make 3 calls to my function to populate array&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateArray(&lt;span class="hljs-string"&gt;"val1"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateArray(&lt;span class="hljs-string"&gt;"val2"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateArray(&lt;span class="hljs-string"&gt;"val3"&lt;/span&gt;)

    &lt;span class="hljs-comment"&gt;'print it&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PrintArray

&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; PopulateArray(value &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;)
   &lt;span class="hljs-comment"&gt;'all arrays are 0 based by default, so the first time it is called, it will create 1 element at position 0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;ReDim&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Preserve&lt;/span&gt; singleArray(currentLength)

    &lt;span class="hljs-comment"&gt;'put the value in the array&lt;/span&gt;
    singleArray(currentLength) = value

    &lt;span class="hljs-comment"&gt;'increment variable so the next time the function is called, the value will be placed one position higher&lt;/span&gt;
    currentLength = currentLength + &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; PrintArray()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; x &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-comment"&gt;'loop through array and print values&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; x = LBound(singleArray) &lt;span class="hljs-keyword"&gt;To&lt;/span&gt; UBound(singleArray)
        Debug.Print singleArray(x)
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Edit: double array sample, knowing the bounds up front&lt;/p&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Option&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Explicit&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; doubleArray() &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;&lt;span class="hljs-comment"&gt;'array declaration that will become two element array&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; currentLength &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-comment"&gt;'variable to keep track of number of elements for array 1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Private&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Command0_Click()
    Debug.Print &lt;span class="hljs-string"&gt;"Accessed from Event "&lt;/span&gt; &amp;amp; doubleArray(&lt;span class="hljs-number"&gt;0&lt;/span&gt;, &lt;span class="hljs-number"&gt;0&lt;/span&gt;) &lt;span class="hljs-comment"&gt;'access from event&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PrintArray &lt;span class="hljs-comment"&gt;'calling function to print array&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Private&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Form_Load()

    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; arrayLength &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;, arrayWidth &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-comment"&gt;'determine bounds of array&lt;/span&gt;
    arrayLength = &lt;span class="hljs-number"&gt;2&lt;/span&gt;&lt;span class="hljs-comment"&gt;'can you write code to determine the length before you start adding records?&lt;/span&gt;
    arrayWidth = &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-comment"&gt;'if you have a fixed number of elements on each "record", this can stay the same&lt;/span&gt;&lt;span class="hljs-keyword"&gt;ReDim&lt;/span&gt; doubleArray(&lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; arrayLength, &lt;span class="hljs-number"&gt;0&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt; arrayWidth)

    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateDoubleArray(&lt;span class="hljs-string"&gt;"val11"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"val12"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateDoubleArray(&lt;span class="hljs-string"&gt;"val21"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"val22"&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PopulateDoubleArray(&lt;span class="hljs-string"&gt;"val31"&lt;/span&gt;, &lt;span class="hljs-string"&gt;"val32"&lt;/span&gt;)

    &lt;span class="hljs-keyword"&gt;Call&lt;/span&gt; PrintArray


&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; PopulateDoubleArray(value &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;, value2 &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;String&lt;/span&gt;)

    &lt;span class="hljs-comment"&gt;'put the value in the array&lt;/span&gt;
    doubleArray(currentLength, &lt;span class="hljs-number"&gt;0&lt;/span&gt;) = value
    doubleArray(currentLength, &lt;span class="hljs-number"&gt;1&lt;/span&gt;) = value2

    &lt;span class="hljs-comment"&gt;'increment variable so the next time the function is called, the value will be placed one position higher&lt;/span&gt;
    currentLength = currentLength + &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; PrintArray()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; x &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Integer&lt;/span&gt;&lt;span class="hljs-comment"&gt;'loop through array and print values&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt; x = LBound(doubleArray) &lt;span class="hljs-keyword"&gt;To&lt;/span&gt; UBound(doubleArray)
        Debug.Print doubleArray(x, &lt;span class="hljs-number"&gt;0&lt;/span&gt;) &amp;amp; &lt;span class="hljs-string"&gt;" "&lt;/span&gt; &amp;amp; doubleArray(x, &lt;span class="hljs-number"&gt;1&lt;/span&gt;)
    &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id="solution_2"&gt;Solution 2:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;If you had &lt;a rel="nofollow noreferrer noopener" href="https://msdn.microsoft.com/en-us/library/bw9t3484%28v=vs.84%29.aspx"&gt;&lt;code&gt;Option Explicit&lt;/code&gt;&lt;/a&gt; in your module, it would have directly given you a compiler error about the ambiguous variable name &lt;code&gt;Arr&lt;/code&gt;.&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;p&gt;You can't have the same name for a variable and a function.&lt;/p&gt;&lt;p&gt;Additionally, this line enforces variable declaration and reports undeclared variables/constants already at compile time. &lt;/p&gt;&lt;p&gt;To have this automatically in new modules, set the &lt;a rel="nofollow noreferrer noopener" href="http://www.fmsinc.com/microsoftaccess/modules/options/index.html"&gt;Require Variable Declaration&lt;/a&gt; option in the VBA Editor. This is really a must have for VBA development.&lt;/p&gt;&lt;/div&gt; 


</description><link>https://rrscils598f08.blogspot.com/2023/09/array-prepared-within-vba-event-how-to.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-882500965543473084.post-8924568161439968996</guid><pubDate>Fri, 29 Sep 2023 08:00:00 +0000</pubDate><atom:updated>2023-09-29T01:00:42.861-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Textjoin</category><category domain="http://www.blogger.com/atom/ns#">Vba</category><title>Vba - Count Empty Cols, Search And Replace</title><description>&lt;div class="question"&gt;I'm learning VBA and trying to do something a bit complicated for me. Here's the deal :  In my 'H' column, I'm using the 'CONCATENATE' formula to get a key of all the elements I wa&lt;/div&gt;&lt;h2 id="solution_1"&gt;Solution 1:

&lt;/h2&gt;&lt;div class="answer-desc"&gt;&lt;p&gt;For sure there are methods to avoid the pattern from the very beginning, but this is a Macro to do a (late) cleanup:&lt;/p&gt;&lt;pre&gt;&lt;code id="code_0" class="hljs language-vbnet"&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt; Cleanup()
    &lt;span class="hljs-keyword"&gt;Dim&lt;/span&gt; cel &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Range, i &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Long&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt; Worksheets(&lt;span class="hljs-string"&gt;"Products"&lt;/span&gt;).UsedRange.Columns(&lt;span class="hljs-string"&gt;"J"&lt;/span&gt;)
        &lt;span class="hljs-keyword"&gt;For&lt;/span&gt; i = &lt;span class="hljs-number"&gt;1&lt;/span&gt;&lt;span class="hljs-keyword"&gt;To&lt;/span&gt;&lt;span class="hljs-number"&gt;5&lt;/span&gt;
           .Replace &lt;span class="hljs-string"&gt;"- - "&lt;/span&gt;, &lt;span class="hljs-string"&gt;"- "&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cel &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; .Cells
            &lt;span class="hljs-keyword"&gt;If&lt;/span&gt; Trim(cel.Value) = &lt;span class="hljs-string"&gt;"-"&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; cel.Clear
        &lt;span class="hljs-keyword"&gt;Next&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;With&lt;/span&gt;&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_0')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;:&lt;/p&gt;&lt;p&gt;Since you and I dont have TextJoin, and it is an excellent solution proposed by the pals, let us have it as UDF. You can add the code below to any non-class code module and use it as User-Defined-Formula (UDF):&lt;/p&gt;&lt;a name='more'&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id="code_1" class="hljs language-sql"&gt;Public &lt;span class="hljs-keyword"&gt;Function&lt;/span&gt; TextJoin(ByVal sep &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; String, ByVal ignoreEmpty &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-type"&gt;Boolean&lt;/span&gt;, ByRef ar &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; Variant) &lt;span class="hljs-keyword"&gt;As&lt;/span&gt; String

    Dim cel &lt;span class="hljs-keyword"&gt;As&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Range&lt;/span&gt;&lt;span class="hljs-keyword"&gt;For&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Each&lt;/span&gt; cel &lt;span class="hljs-keyword"&gt;In&lt;/span&gt; ar
        If &lt;span class="hljs-built_in"&gt;Trim&lt;/span&gt;(cel.Text) &lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt; "" &lt;span class="hljs-keyword"&gt;Or&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Not&lt;/span&gt; ignoreEmpty &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt;
            If TextJoin &lt;span class="hljs-operator"&gt;&amp;lt;&amp;gt;&lt;/span&gt; "" &lt;span class="hljs-keyword"&gt;Then&lt;/span&gt; TextJoin &lt;span class="hljs-operator"&gt;=&lt;/span&gt; TextJoin &lt;span class="hljs-operator"&gt;+&lt;/span&gt; sep
            TextJoin &lt;span class="hljs-operator"&gt;=&lt;/span&gt; TextJoin &lt;span class="hljs-operator"&gt;+&lt;/span&gt; cel.Text
        &lt;span class="hljs-keyword"&gt;End&lt;/span&gt; If
    Next
&lt;span class="hljs-keyword"&gt;End&lt;/span&gt;&lt;span class="hljs-keyword"&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class="copy-btn btn btn-secondary btn-sm" onclick="copyCode(this,'code_1')"&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</description><link>https://rrscils598f08.blogspot.com/2023/09/vba-count-empty-cols-search-and-replace.html</link><thr:total>0</thr:total><author>rrscils598f08@gmail.com (Mitchell Kassulke)</author></item></channel></rss>