<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-5520865691253935674</id><updated>2023-10-07T11:56:14.867-07:00</updated><category term="Excel"/><category term="Vba"/><category term="Excel Formula"/><category term="C#"/><category term="Python"/><category term="Apache Poi"/><category term="Java"/><category term=".net"/><category term="Openpyxl"/><category term="Csv"/><category term="Date"/><category term="Excel 2007"/><category term="Excel 2010"/><category term="Excel Addins"/><category term="Html"/><category term="Sql Server"/><category term="Vb.net"/><category term="Vsto"/><category term="Xml"/><category term="Activex"/><category term="Arrays"/><category term="Com"/><category term="Delphi"/><category term="Excel 2003"/><category term="Excel Interop"/><category term="Image"/><category term="Macros"/><category term="Ms Access"/><category term="Ms Word"/><category term="Php"/><category term="Powerpoint"/><category term="Python 3.x"/><category term="R"/><category term="Rows"/><category term="Sql"/><category term="Web Scraping"/><category term="Xlsxwriter"/><category term="Adfs"/><category term="Adodb"/><category term="Advanced Filter"/><category term="Array Formulas"/><category term="Backup"/><category term="Batch File"/><category term="Bloomberg"/><category term="Button"/><category term="C++"/><category term="Cell Formatting"/><category term="Charts"/><category term="Client"/><category term="Coldfusion"/><category term="Combobox"/><category term="Comments"/><category term="Compiler Errors"/><category term="Conditional"/><category term="Conditional Formatting"/><category term="Connection"/><category term="Copy"/><category term="Count"/><category term="Currency"/><category term="Database"/><category term="Datatable"/><category term="Debugging"/><category term="Dictionary"/><category term="Dll"/><category term="Drop Down Menu"/><category term="Dynamic"/><category term="Economics"/><category term="Email"/><category term="Epplus"/><category term="Equals"/><category term="Error Checking"/><category term="Etl"/><category term="Excel 2011"/><category term="Excel 2016"/><category term="Excel Match"/><category term="Export"/><category term="Export To Excel"/><category term="File Upload"/><category term="Foreach"/><category term="Formula"/><category term="If Statement"/><category term="Internet Explorer"/><category term="Internet Explorer 11"/><category term="Interop"/><category term="Inventory"/><category term="Inventory Management"/><category term="Irr"/><category term="Javascript"/><category term="Javascript Framework"/><category term="Labview"/><category term="Listobject"/><category term="Lookup"/><category term="Loops"/><category term="Manual"/><category term="Matching"/><category term="Modal Dialog"/><category term="Mysql"/><category term="Named Ranges"/><category term="Nullpointerexception"/><category term="Numpy"/><category term="Odoo"/><category term="Office 2007"/><category term="Office Js"/><category term="Office365"/><category term="Oledb"/><category term="Oop"/><category term="Optimization"/><category term="Oracle"/><category term="Oracle Apex"/><category term="Outlook"/><category term="Pandas"/><category term="Parsing"/><category term="Paste"/><category term="Pdf"/><category term="Powerbi"/><category term="Powerquery"/><category term="Powershell"/><category term="Range"/><category term="Recursion"/><category term="Replace"/><category term="Row"/><category term="Rtd"/><category term="Scientific Notation"/><category term="Sharepoint"/><category term="Sharepoint 2007"/><category term="Show Hide"/><category term="Sku"/><category term="Sorting"/><category term="Spreadsheet"/><category term="Sql Server 2019"/><category term="Ssis"/><category term="Statistics"/><category term="Tcl"/><category term="User Controls"/><category term="Userform"/><category term="Vbscript"/><category term="Visual Studio"/><category term="Vlookup"/><category term="Webbrowser Control"/><category term="Windows"/><category term="Wolfram Mathematica"/><category term="Worksheet Function"/><category term="Xlwings"/><category term="Xpath"/><category term="Xssf"/><title type='text'>norfaezahsuhaimi</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default?start-index=26&amp;max-results=25'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>189</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-1478042295770435288</id><published>2023-10-07T11:55:00.001-07:00</published><updated>2023-10-07T11:55:42.896-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Php"/><title type='text'>How To Access An .xlsb File By Php?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I need to access an .xlsb file that does the same function as this code that accesses a .csv file:  Access the .xlsb file, scroll through the columns and rows, and display the row&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You can use the &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.easyxls.com/component-excel-library&quot;&gt;PHP Excel library&lt;/a&gt; from &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.easyxls.com&quot;&gt;EasyXLS&lt;/a&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-php&quot;&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$xls&lt;/span&gt; = &lt;span class=&quot;hljs-keyword&quot;&gt;new&lt;/span&gt; COM(&lt;span class=&quot;hljs-string&quot;&gt;&quot;EasyXLS.ExcelDocument&quot;&lt;/span&gt;);
&lt;span class=&quot;hljs-variable&quot;&gt;$rows&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$xls&lt;/span&gt;-&amp;gt;easy_ReadXLSBActiveSheet_AsList(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Trabalhos.xlsb&quot;&lt;/span&gt;);
&lt;span class=&quot;hljs-keyword&quot;&gt;for&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$row1&lt;/span&gt;=&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;; &lt;span class=&quot;hljs-variable&quot;&gt;$row1&lt;/span&gt;&amp;lt;&lt;span class=&quot;hljs-variable&quot;&gt;$rows&lt;/span&gt;-&amp;gt;size(); &lt;span class=&quot;hljs-variable&quot;&gt;$row1&lt;/span&gt;++)
{
    &lt;span class=&quot;hljs-variable&quot;&gt;$rowLine&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$rows&lt;/span&gt;-&amp;gt;elementAt(&lt;span class=&quot;hljs-variable&quot;&gt;$row1&lt;/span&gt;);
        &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; (&lt;span class=&quot;hljs-variable&quot;&gt;$row1&lt;/span&gt; == &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;) {
            &lt;span class=&quot;hljs-variable&quot;&gt;$column1&lt;/span&gt;[&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;].&lt;span class=&quot;hljs-string&quot;&gt;&quot;&amp;lt;br&amp;gt;&quot;&lt;/span&gt;;
            &lt;span class=&quot;hljs-variable&quot;&gt;$valor1&lt;/span&gt; = &lt;span class=&quot;hljs-variable&quot;&gt;$row&lt;/span&gt;-&amp;gt;elementAt(&lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;);
        }
}
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You can find some more code samples about &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://www.easyxls.com/manual/basics/import-from-xlsb-file-format.html&quot;&gt;importing data from xlsb file&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;For your purpose you can use &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://github.com/PHPOffice/PHPExcel&quot;&gt;PHPOffice/PHPExcel&lt;/a&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/1478042295770435288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-access-xlsb-file-by-php.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1478042295770435288'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1478042295770435288'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-access-xlsb-file-by-php.html' title='How To Access An .xlsb File By Php?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-4746534764903059129</id><published>2023-10-07T09:36:00.001-07:00</published><updated>2023-10-07T09:36:00.879-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Access"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Sql Query To Pull Records Of Exception Entry</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am new to Excel VBA. I have a UserForm in which I am trying to populate records of exception entered by employee for the current month. I have a database called Ofc. Under which&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;A couple of points:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;I&#39;d suggest you parameterise your query. You only need one daft so-and-so to rename his ID &quot;0; DROP TABLE Codeusage&quot; or some such hilarious prank and unsanitised SQL text commands can give you a whole world of hurt.&lt;/li&gt;&lt;li&gt;Column names with spaces are ripe for causing trouble and are usually considered poor design, so I&#39;d remove those spaces if you possibly can. If not then you&#39;ll need to &lt;em&gt;quote&lt;/em&gt; your column names. You&#39;ll have to check what works for your particular system but straight brackets would be a good first bet.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;You&#39;ll have to adjust the code below to meet the specific requirements of your database (you don&#39;t mention which one), but this is what I would do for something like SQL Server or SQLite. Note, I&#39;ve referenced &lt;code&gt;Microsoft ActiveX Data Objects 6.1 Library&lt;/code&gt; via Tools -&amp;gt; References):&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; conn &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; ADODB.Connection
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; cmd &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; ADODB.Command
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; prm &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; ADODB.Parameter
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; rs &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; ADODB.Recordset
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; firstOfMonth &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; lastOfMonth &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; PeoplesoftId &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Open the database connection&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; conn = &lt;span class=&quot;hljs-built_in&quot;&gt;New&lt;/span&gt; ADODB.Connection
conn.CursorLocation = adUseClient
conn.Open &lt;span class=&quot;hljs-string&quot;&gt;&quot;[Your connection string goes here]&quot;&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Define your query parameters&lt;/span&gt;
PeoplesoftId = &lt;span class=&quot;hljs-string&quot;&gt;&quot;43243312&quot;&lt;/span&gt;
firstOfMonth = DateSerial(Year(Now), Month(Now), &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)
lastOfMonth = DateSerial(Year(firstOfMonth), Month(firstOfMonth) + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Create your command&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; cmd = &lt;span class=&quot;hljs-built_in&quot;&gt;New&lt;/span&gt; ADODB.Command
cmd.ActiveConnection = conn

&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Command text&lt;/span&gt;
cmd.CommandText = &lt;span class=&quot;hljs-string&quot;&gt;&quot;SELECT * FROM CodeUsage&quot;&lt;/span&gt; &amp;amp; _
                  &lt;span class=&quot;hljs-string&quot;&gt;&quot; WHERE PeoplesoftId=?&quot;&lt;/span&gt; &amp;amp; _
                  &lt;span class=&quot;hljs-string&quot;&gt;&quot; AND Date_of_exception&amp;gt;=?&quot;&lt;/span&gt; &amp;amp; _
                  &lt;span class=&quot;hljs-string&quot;&gt;&quot; AND Date_of_exception&amp;lt;=?&quot;&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;note I&#39;ve replaced your spaces with underscore&lt;/span&gt;

cmd.CommandType = adCmdText

&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Command parameters&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; prm = cmd.CreateParameter(, adChar, adParamInput, Len(PeoplesoftId), PeoplesoftId)
cmd.Parameters.Append prm

&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; prm = cmd.CreateParameter(, adDate, adParamInput, , firstOfMonth)
cmd.Parameters.Append prm

&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; prm = cmd.CreateParameter(, adDate, adParamInput, , lastOfMonth)
cmd.Parameters.Append prm

&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Execute the command - returns a RecordSet&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; rs = cmd.Execute

&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Close the connection&lt;/span&gt;
conn.Close
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/4746534764903059129/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/sql-query-to-pull-records-of-exception.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4746534764903059129'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4746534764903059129'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/sql-query-to-pull-records-of-exception.html' title='Sql Query To Pull Records Of Exception Entry'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-3758578471981241038</id><published>2023-10-07T08:29:00.001-07:00</published><updated>2023-10-07T08:29:38.186-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Equals"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Range"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>How To Check If Two Ranges Value Is Equal</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I want to merge cells in columns, if there is the same value in whole row.   Eg. If A1:G1 range is the same as A2:G2 I want to merge A1:A2 cells, B1:B2 to G1:G2. With my code below&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The issue is that … &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-scss&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Range&lt;/span&gt;(Cells(i, &lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;), &lt;span class=&quot;hljs-built_in&quot;&gt;Cells&lt;/span&gt;(i, &lt;span class=&quot;hljs-number&quot;&gt;24&lt;/span&gt;))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Value&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;returns an array of values, but you cannot compare an array of values with &lt;code&gt;=&lt;/code&gt;. Therefore you need to loop throug all these values and compare each value with the corresponding value in &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-scss&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Range&lt;/span&gt;(Cells(i - &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;), &lt;span class=&quot;hljs-built_in&quot;&gt;Cells&lt;/span&gt;(i - &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;24&lt;/span&gt;))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Value&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Since you already have this loop just move your &lt;code&gt;If&lt;/code&gt; statement to check this into the loop: &lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; iRow &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, iCol &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, LastRow &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;
LastRow = Cells(Rows.Count, &lt;span class=&quot;hljs-number&quot;&gt;6&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).row
&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; iRow = LastRow &lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Step&lt;/span&gt; -&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; iCol = &lt;span class=&quot;hljs-number&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;24&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Step&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Cells(iRow, iCol).Value = Cells(iRow - &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, iCol).Value &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
            Range(Cells(iRow, iCol), Cells(iRow - &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, iCol)).Merge
        &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; iCol 
&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; iRow 
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Note that I changed the variable naming to more meaningful names. This also avoids using &lt;code&gt;Row&lt;/code&gt; as variable name which is alerady used by Excel itself.&lt;/p&gt;&lt;hr&gt;&lt;p&gt;Edit according comments&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Explicit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Test()
    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; RangeToMerge &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range
    &lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; RangeToMerge = Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;C5:F14&quot;&lt;/span&gt;)

    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; FirstMergeRow &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;
    FirstMergeRow = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; iRow &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, iCol &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; iRow = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt; RangeToMerge.Rows.Count - &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Join&lt;/span&gt;(Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Transpose(RangeToMerge.Rows(FirstMergeRow).Value)), &lt;span class=&quot;hljs-string&quot;&gt;&quot;|&quot;&lt;/span&gt;) &amp;lt;&amp;gt; _
           &lt;span class=&quot;hljs-keyword&quot;&gt;Join&lt;/span&gt;(Application.WorksheetFunction.Transpose(Application.WorksheetFunction.Transpose(RangeToMerge.Rows(iRow + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;).Value)), &lt;span class=&quot;hljs-string&quot;&gt;&quot;|&quot;&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; iRow &amp;lt;&amp;gt; FirstMergeRow &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; iCol = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt; RangeToMerge.Columns.Count
                    Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
                    RangeToMerge.Cells(FirstMergeRow, iCol).Resize(rowsize:=iRow - FirstMergeRow + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;).Merge
                    Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; iCol
            &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;
            FirstMergeRow = iRow + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; iRow

    &lt;span class=&quot;hljs-comment&quot;&gt;&#39;merge last ones&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; iRow &amp;lt;&amp;gt; FirstMergeRow &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; iCol = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt; RangeToMerge.Columns.Count
            Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
            RangeToMerge.Cells(FirstMergeRow, iCol).Resize(rowsize:=iRow - FirstMergeRow + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;).Merge
            Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; iCol
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Will turn the following&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/5xgt3.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/5xgt3.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;into &lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/RYcbc.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/RYcbc.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The &lt;code&gt;value&lt;/code&gt; property of a range returns an array if the range has more than one cell. You can either compare the values of each element in a loop, or you can use &lt;code&gt;join()&lt;/code&gt; to convert the arrays to strings and then compare those (see &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/questions/31167156/without-loops-how-to-check-if-two-arrays-are-equal-or-not&quot;&gt;this answer&lt;/a&gt;).&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/3758578471981241038/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-check-if-two-ranges-value-is.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3758578471981241038'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3758578471981241038'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-check-if-two-ranges-value-is.html' title='How To Check If Two Ranges Value Is Equal'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-6364928315436341147</id><published>2023-10-07T07:54:00.001-07:00</published><updated>2023-10-07T07:54:42.274-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Copy Data Between Excel Spreadsheets With A Given Value As A Parameter</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Say I have two spreadsheets. One of the spreadsheets has a table like this:   **Sheet 1**   A        B        C        D 1 Name     Age      Rank     Number  2 George   22       Ma&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;vlookup would be the easiest way to go.
I will use cell B2 in sheet2 as the reference to try to explain the function
&lt;code&gt;=VLOOKUP(A2,Sheet1!$A$2:$D$5,2,FALSE)&lt;/code&gt;
The first parameter is the data you are using for a lookup - you may want to change that to &lt;code&gt;$A2&lt;/code&gt; if you copy the formula around the sheet
The second parameter is where the data is that excel needs to find the value you referenced in the first parameter - use dollar signs. The data doesn&#39;t tend to move
The third parameter tells excel what info to return - the 2 means give me the 2nd piece of data
The last parameter tells excel if it can use a close match (&lt;code&gt;FALSE&lt;/code&gt; for an exact match) &lt;/p&gt;&lt;p&gt;Now to follow Excel and see what it returns..... &lt;/p&gt;&lt;p&gt;First, it looks for &lt;code&gt;George&lt;/code&gt; in the data (it knows it has to be an exact match from the fourth parameter)
Next, it finds the row &lt;code&gt;George -- 22 -- Master -- 12&lt;/code&gt; and gives the function the second value (&lt;code&gt;22&lt;/code&gt; in this case)&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/6364928315436341147/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/copy-data-between-excel-spreadsheets.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6364928315436341147'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6364928315436341147'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/copy-data-between-excel-spreadsheets.html' title='Copy Data Between Excel Spreadsheets With A Given Value As A Parameter'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-1320360977130554236</id><published>2023-10-07T06:50:00.001-07:00</published><updated>2023-10-07T06:50:12.943-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Check Is Destination Directory Exist Then Proceed If Not Then Create It And Proceed Afterwards</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a button on one of the worksheets that lets user to continue with his task to save his/her template as a separate workbook in the folder. Here is my code Private Sub Continu&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I am going to modularize your code a little bit:&lt;/p&gt;&lt;p&gt;First get the directory path here&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-php&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;getDirectoryPath&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;/span&gt;)
    &lt;span class=&quot;hljs-title&quot;&gt;getDirectoryPath&lt;/span&gt; = &lt;span class=&quot;hljs-title&quot;&gt;ThisWorkbook&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot;&gt;Path&lt;/span&gt; &amp;amp; &lt;span class=&quot;hljs-title&quot;&gt;Application&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot;&gt;PathSeparator&lt;/span&gt; &amp;amp; &lt;span class=&quot;hljs-title&quot;&gt;Settings&lt;/span&gt;.&lt;span class=&quot;hljs-title&quot;&gt;Range&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;C45&quot;&lt;/span&gt;&lt;/span&gt;).&lt;span class=&quot;hljs-title&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-title&quot;&gt;Function&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You can create the directory using this function&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; createDirectory(directoryPath)
    MkDir directoryPath
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;You can check if a directory exists or not using &lt;code&gt;Dir&lt;/code&gt; function&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-rust&quot;&gt;&lt;span class=&quot;hljs-title function_ invoke__&quot;&gt;Dir&lt;/span&gt;(directoryPath, vbDirectory) &lt;span class=&quot;hljs-symbol&quot;&gt;&#39;empty&lt;/span&gt; string means directoryPath doesn&lt;span class=&quot;hljs-symbol&quot;&gt;&#39;t&lt;/span&gt; exist
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The final function on button click:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Private&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; ContinueButton_Click()
    Application.ScreenUpdating = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;
    Sheets(cmbSheet.Value).Visible = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;
    directoryPath = getDirectoryPath
    &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Creating the directory only if it doesn&#39;t exist&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Dir(directoryPath, vbDirectory) = &lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
         createDirectory directoryPath
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;
    Application.&lt;span class=&quot;hljs-keyword&quot;&gt;Goto&lt;/span&gt; Sheets(cmbSheet.Value).[a22], &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;
    Application.ScreenUpdating = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;
    Unload &lt;span class=&quot;hljs-keyword&quot;&gt;Me&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I created a macro that will save as pdf certain tabs of my excel in a relative (variable)folder.
It will use the contract reference to create a subfolder, such subfolder label is exactly the contract reference. If subfolder already exists it just creates the files in it, else (subfolder does not exist) then it creates the folder and save the files in it. &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Gera_PDF_MG_Nao_Produtor_Sem_Ajuste()

    Gera_PDF_MG_Nao_Produtor_Sem_Ajuste Macro



    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; MyFolder &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; LaudoName &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; NF1Name &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;

    MyFolder = ThisWorkbook.path &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;\&quot;&lt;/span&gt; &amp;amp; Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;C9&quot;&lt;/span&gt;)
    LaudoName = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;K27&quot;&lt;/span&gt;)
    NF1Name = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;MG sem crédito e sem ajuste&quot;&lt;/span&gt;).Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Q3&quot;&lt;/span&gt;)

    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;
    Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D:P&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;
    Selection.EntireColumn.Hidden = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Dir(MyFolder, vbDirectory) &amp;lt;&amp;gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;\&quot;&lt;/span&gt; &amp;amp; LaudoName &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;.pdf&quot;&lt;/span&gt;, Quality:=xlQualityMinimum, _
    IncludeDocProperties:=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;, IgnorePrintAreas:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, OpenAfterPublish:= _
    &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;

    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;MG sem crédito e sem ajuste&quot;&lt;/span&gt;).ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;\&quot;&lt;/span&gt; &amp;amp; NF1Name &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;.pdf&quot;&lt;/span&gt;, Quality:=xlQualityMinimum, _
    IncludeDocProperties:=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;, IgnorePrintAreas:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, OpenAfterPublish:= _
    &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
    MkDir MyFolder
    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;\&quot;&lt;/span&gt; &amp;amp; LaudoName &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;.pdf&quot;&lt;/span&gt;, Quality:=xlQualityMinimum, _
    IncludeDocProperties:=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;, IgnorePrintAreas:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, OpenAfterPublish:= _
    &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;

    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;MG sem crédito e sem ajuste&quot;&lt;/span&gt;).ExportAsFixedFormat Type:=xlTypePDF, filename:=MyFolder &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;\&quot;&lt;/span&gt; &amp;amp; NF1Name &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot;.pdf&quot;&lt;/span&gt;, Quality:=xlQualityMinimum, _
    IncludeDocProperties:=&lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;, IgnorePrintAreas:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;, OpenAfterPublish:= _
    &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;

    Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Laudo&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;
    Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;C:Q&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;
    Selection.EntireColumn.Hidden = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
    Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-cpp&quot;&gt;&lt;span class=&quot;hljs-function&quot;&gt;If &lt;span class=&quot;hljs-title&quot;&gt;Dir&lt;/span&gt;&lt;span class=&quot;hljs-params&quot;&gt;(Fldrpath, vbDirectory)&lt;/span&gt;&lt;/span&gt;= &lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt; Then
MkDir Fldrpath
End If
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Fldrpath&lt;/strong&gt; refer to the Folderpath if Folder not found &lt;strong&gt;MkDir&lt;/strong&gt; creates the folder&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/1320360977130554236/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/check-is-destination-directory-exist.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1320360977130554236'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1320360977130554236'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/check-is-destination-directory-exist.html' title='Check Is Destination Directory Exist Then Proceed If Not Then Create It And Proceed Afterwards'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-6138426719138049911</id><published>2023-10-07T03:36:00.001-07:00</published><updated>2023-10-07T03:36:21.973-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel Addins"/><category scheme="http://www.blogger.com/atom/ns#" term="Office Js"/><category scheme="http://www.blogger.com/atom/ns#" term="Office365"/><title type='text'>Excel Js Add-in Manifest Requirements Section</title><content type='html'>&lt;div class=&quot;question&quot;&gt;we have excel js add with custom function support and because of it, this add-in works just in excel office 365 version. here we met a problem - &#39;npm validate&#39; define this add-in a&lt;/div&gt;
&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;
&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Custom Functions use separate requirement sets from the core Excel JavaScript APIs. You could refer to this page for Custom Functions requirement sets:
&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/office/dev/add-ins/excel/custom-functions-requirement-sets&quot;&gt;Custom Functions requirement sets&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 
&lt;br&gt;
</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/6138426719138049911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-js-add-in-manifest-requirements.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6138426719138049911'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6138426719138049911'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-js-add-in-manifest-requirements.html' title='Excel Js Add-in Manifest Requirements Section'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-4173550708715308089</id><published>2023-10-07T00:35:00.001-07:00</published><updated>2023-10-07T00:35:25.553-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><title type='text'>Merge Excel Files Into One</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a few hundred Excel files, where each file has some data on the first sheet. I&#39;ve been asked to write a console application in C# which merges all of the Excel files togethe&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You&#39;ll need to use the Microsoft Excel Interop library. &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;You should be able to add a reference, in the com tab, to Microsoft Excel 11 Object Library. &lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx&lt;/a&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This is an easy task for a neat little program called Bulk File Merger (they have a Mac version called Excel File Merger). I managed to merge over 300 files in a matter of minutes. You can also merge csv files, which takes even less time. We banged out over 1300 csv files in seconds. Scary.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;It&#39;s not free (a developer license is $ 425) but &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://www.gemboxsoftware.com/&quot;&gt;GemBox&lt;/a&gt; has a very good library that is way faster than using the office objects. We use it in my current project since a year and a half, and it has consistently performed very well for us.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_4&quot;&gt;Solution 4:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Look into Visual Studio Tools for Office (VSTO).
You can open workbooks in code and use a lot of the excel functionality, as well as copying worksheets like you&#39;ve said you need to do.&lt;/p&gt;&lt;p&gt;For resources, &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://social.msdn.microsoft.com/forums/en-US/vsto/thread/b31bf687-2549-436a-8997-c11c9f3258ed/&quot;&gt;this MSDN forum post&lt;/a&gt; demonstrates opening excel files and copying worksheets. Hopefully this will get you on the right direction. &lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_5&quot;&gt;Solution 5:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Of course you can do Tool-&amp;gt;Compare-&amp;gt;Merge Workbooks. And within Excel as Joshua mentioned there is the merge method in the COM Interop libraries. If you need some help let me know I work heavily in Excel and may be able to help you out on a small fee basis.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/4173550708715308089/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/merge-excel-files-into-one.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4173550708715308089'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4173550708715308089'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/merge-excel-files-into-one.html' title='Merge Excel Files Into One'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-2272076919347720629</id><published>2023-10-06T22:04:00.001-07:00</published><updated>2023-10-06T22:04:26.977-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Excel-vba; Copy Data From Excel And Paste It In To A Word Template At Different Places</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have some data in an Excel Sheet which have been pull from the master data in another sheet by the VBA. The data is showing in excel sheet in column A &amp; B. And I have an MS-W&lt;/div&gt;

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

&lt;/h2&gt;
&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Assuming that your data is in cells B1 to B7 of &quot;Sheet1&quot;, then the following code will paste the required text into the document &quot;C:\TestFolder\Test.docx&quot;. You can obviously edit the filenames and pathnames to suit.&lt;/p&gt;
&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; PasteStuffIntoWord()
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; ws &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; TextToPaste &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; objWord &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; objSelection &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; &lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;

&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; ws = Worksheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Sheet1&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; ws
    TextToPaste = &lt;span class=&quot;hljs-string&quot;&gt;&quot;An estimate amounting to Rs. &quot;&lt;/span&gt; &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B1&quot;&lt;/span&gt;).Value &amp;amp; _
    &lt;span class=&quot;hljs-string&quot;&gt;&quot; based on approved rates for the above &quot;&lt;/span&gt; &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B2&quot;&lt;/span&gt;).Value &amp;amp; _
    &lt;span class=&quot;hljs-string&quot;&gt;&quot; was sanctioned by the competent authority. Against this estimate tenders amounting to Rs. &quot;&lt;/span&gt; _
    &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B3&quot;&lt;/span&gt;).Value &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; were invited vide Tender No. &quot;&lt;/span&gt; &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B4&quot;&lt;/span&gt;).Value &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; Dated &quot;&lt;/span&gt; _
    &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B5&quot;&lt;/span&gt;).Value &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; which has opened on &quot;&lt;/span&gt; &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B7&quot;&lt;/span&gt;).Value &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; This estimate for Rs. &quot;&lt;/span&gt; _
    &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B1&quot;&lt;/span&gt;).Value &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; has been approved on &quot;&lt;/span&gt; &amp;amp; .Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B5&quot;&lt;/span&gt;).Value
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;

    &lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objWord = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;word.Application&quot;&lt;/span&gt;)
    objWord.documents.Open &lt;span class=&quot;hljs-string&quot;&gt;&quot;C:\TestFolder\Test.docx&quot;&lt;/span&gt;
    objWord.Visible = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;
    &lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objSelection = objWord.Selection
    objSelection.TypeText TextToPaste

&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt; &lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 
&lt;br&gt;
</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/2272076919347720629/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-copy-data-from-excel-and.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2272076919347720629'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2272076919347720629'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-copy-data-from-excel-and.html' title='Excel-vba; Copy Data From Excel And Paste It In To A Word Template At Different Places'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-6243335809795719920</id><published>2023-10-06T21:41:00.001-07:00</published><updated>2023-10-06T21:41:02.504-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Copying A Variable Based Range Of Cells To Another Range</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Hello from my code it should be evident what I am trying to do at this point. I am attempting to copy a range of cells from a static portion of a worksheet to a created column but&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot; style=&quot;height: auto !important;&quot;&gt;&lt;p&gt;You should &lt;strong&gt;use &lt;code&gt;.Value&lt;/code&gt; or &lt;code&gt;.Value2&lt;/code&gt; to transfer data between to ranges&lt;/strong&gt; like this :&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-bash&quot;&gt;Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2: D&quot;&lt;/span&gt; &amp;amp; LastAth).Value2 = Ath.Range(Ath.Cells(2, x), Ath.Cells(LastAth, x)).Value2
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;The &lt;strong&gt;main difference between these two&lt;/strong&gt; is : &lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;code&gt;.Value2&lt;/code&gt; gives you the underlying value of the cell (unformatted data)&lt;/li&gt;&lt;li&gt;&lt;code&gt;.Value&lt;/code&gt; gives you the formatted value of the cell&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;For more details, take a look at &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://fastexcel.wordpress.com/2011/11/30/text-vs-value-vs-value2-slow-text-and-how-to-avoid-it/&quot;&gt;Charles William&#39;s blog here.&lt;/a&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;hr&gt;&lt;p&gt;&lt;strong&gt;As you seem to be working on two sheets&lt;/strong&gt; (not on the &quot;mapping&quot; one in the code you gave, if I got that right. If not just change &lt;code&gt;Ath.&lt;/code&gt; to &lt;code&gt;Map.&lt;/code&gt; where it need to be), &lt;strong&gt;don&#39;t forget to use the references&lt;/strong&gt; you created (I added them everywhere, even before &lt;code&gt;Rows.Count&lt;/code&gt; and &lt;code&gt;Columns.Count&lt;/code&gt; to avoid errors if you open an old document on a new Excel version)&lt;/p&gt;&lt;p&gt;I got rid of the &lt;code&gt;Select&lt;/code&gt;s and shorten code where I could, but I let the &quot;Mapping&quot; sheet as I guessed you&#39;ll use it later in your code.&lt;/p&gt;&lt;p&gt;Also don&#39;t forget to free your abject variables like this, when you won&#39;t use it afterwards : &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_10&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Ath = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Map = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_10&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;hr&gt;&lt;hr&gt;&lt;p&gt;Here is &lt;strong&gt;your code corrected, cleaned and tested&lt;/strong&gt; :&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_11&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Mapping()

&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; Map &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet, _
    Ath &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet, _
    LastAth &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, _
    LastMap &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, _
    CLastAth &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, _
    x &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Integer&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Ath = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Athena Greek God&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Map = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Mapping&quot;&lt;/span&gt;)
LastMap = Map.Cells(Map.Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;D&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).Row
LastAth = Ath.Cells(Ath.Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).Row

Ath.Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A:D&quot;&lt;/span&gt;).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:D1&quot;&lt;/span&gt;).Value = Array(&lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 2&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 3&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 4&quot;&lt;/span&gt;)
Ath.Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A:D&quot;&lt;/span&gt;).AutoFit

&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:D&quot;&lt;/span&gt; &amp;amp; LastAth).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -&lt;span class=&quot;hljs-number&quot;&gt;0.149998474074526&lt;/span&gt;
    .PatternTintAndShade = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;


CLastAth = Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, Ath.Columns.Count).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlToLeft).Column

&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; x = CLastAth &lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Step&lt;/span&gt; -&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, x) &amp;lt;&amp;gt; &lt;span class=&quot;hljs-string&quot;&gt;&quot;The Principals Book&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
        Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2: D&quot;&lt;/span&gt; &amp;amp; LastAth).Value = Ath.Range(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath.Cells(LastAth, x)).Value
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; x

&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Ath = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Map = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_11&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Take out the space after the :&lt;/p&gt;&lt;p&gt;I have also chopped your code down, Dimmed X and removed the selects for you:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_12&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Mapping()

&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; Map &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet, Ath &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet, lastmap &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, lastath &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, X &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;, Clastath &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Ath = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Athena Greek God&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; Map = Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Mapping&quot;&lt;/span&gt;)
lastmap = Map.Cells(Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;D&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).Row
lastath = Ath.Cells(Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).Row

Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A:D&quot;&lt;/span&gt;).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:D1&quot;&lt;/span&gt;) = Array(&lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 2&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 3&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 4&quot;&lt;/span&gt;)
Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A:D&quot;&lt;/span&gt;).AutoFit
&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:D&quot;&lt;/span&gt; &amp;amp; lastath).Interior
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    .ThemeColor = xlThemeColorDark1
    .TintAndShade = -&lt;span class=&quot;hljs-number&quot;&gt;0.149998474074526&lt;/span&gt;
    .PatternTintAndShade = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;

Clastath = Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, Columns.Count).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlToLeft).Column

&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; X = Clastath &lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Step&lt;/span&gt; -&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, X) = &lt;span class=&quot;hljs-string&quot;&gt;&quot;The Principals Book&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath) = Range(Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, X), Cells(lastath, X))
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_12&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Edit: Also dimmed Clastath as long&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Actually, it is not really evident what this code should achieve, tell you why:
Two worksheets are defined but only one of them is used, also It&#39;s not clear to which worksheet the code is to be applied. As it stand now, the code is applied to whatever worksheet is active.&lt;/p&gt;&lt;p&gt;See the code below with adjustments and comments.
The code assumes the procedure should be apply to the Ath worksheet (change as needed)&lt;/p&gt;&lt;p&gt;Although the changes are explained, do let me know of any questions you might have about.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_13&quot; class=&quot;hljs language-sql&quot;&gt;Option Explicit
Option Base &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;

Sub Mapping()
Rem Worksheet &quot;Map&quot; &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;only&lt;/span&gt; used &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; obtain lastmap which &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt; never used
Rem Therefore theese line &lt;span class=&quot;hljs-keyword&quot;&gt;are&lt;/span&gt; commented &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt; they do &lt;span class=&quot;hljs-keyword&quot;&gt;not&lt;/span&gt; play &lt;span class=&quot;hljs-keyword&quot;&gt;any&lt;/span&gt; role &lt;span class=&quot;hljs-keyword&quot;&gt;in&lt;/span&gt; the &lt;span class=&quot;hljs-keyword&quot;&gt;procedure&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;Dim Map As Worksheet
&#39;&lt;/span&gt;Dim lastmap &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Long
&lt;span class=&quot;hljs-string&quot;&gt;&#39;Set Map = Sheets(&quot;Mapping&quot;)
&#39;&lt;/span&gt;lastmap &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; Map.Cells(Rows.Count, &quot;D&quot;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).&lt;span class=&quot;hljs-type&quot;&gt;Row&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39; NOT USED?

Rem Set array with titles - easy to maintain, and use to command all further intructions avoiding hard codding
Dim aTitles As Variant
aTitles = [{&quot;EDITED&quot;,&quot;EDITED 2&quot;,&quot;EDITED 3&quot;,&quot;EDITED 4&quot;}]

Dim Ath As Worksheet
Dim lastath As Long
Dim Clastath As Integer
Dim X As Integer

    Set Ath = Sheets(&quot;Athena Greek God&quot;)

    Rem It&#39;&lt;/span&gt;s &lt;span class=&quot;hljs-keyword&quot;&gt;not&lt;/span&gt; clear &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; which worksheet the code &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; be applied?
    Rem Actually it &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt; applied &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; whatever worksheet &lt;span class=&quot;hljs-keyword&quot;&gt;is&lt;/span&gt; active
    Rem This code assumes the &lt;span class=&quot;hljs-keyword&quot;&gt;procedure&lt;/span&gt; should be apply &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; the Ath worksheet
    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Ath &lt;span class=&quot;hljs-string&quot;&gt;&#39;(change as needed)
        lastath = .Cells(Rows.Count, 1).End(xlUp).Row
        .Cells(1).Resize(, UBound(aTitles)).EntireColumn.Insert     &#39;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Using&lt;/span&gt; Titles &lt;span class=&quot;hljs-keyword&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;insert&lt;/span&gt; required number &lt;span class=&quot;hljs-keyword&quot;&gt;of&lt;/span&gt; columns
        &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Range&lt;/span&gt;(.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;), .Cells(lastath, UBound(aTitles)))  &lt;span class=&quot;hljs-string&quot;&gt;&#39;Working with the range to be updated
            .Rows(1).Value = aTitles
            .Columns.AutoFit
            .Interior.Color = RGB(217, 217, 217)                    &#39;&lt;/span&gt;Simplify &lt;span class=&quot;hljs-keyword&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;set&lt;/span&gt; color

            Clastath &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; .Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, Columns.Count).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlToLeft).&lt;span class=&quot;hljs-keyword&quot;&gt;Column&lt;/span&gt;

            Rem Use &quot;Step -1&quot; if you have more than &lt;span class=&quot;hljs-keyword&quot;&gt;one&lt;/span&gt; cell &lt;span class=&quot;hljs-keyword&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; &quot;The Principals Book&quot;
            Rem &lt;span class=&quot;hljs-keyword&quot;&gt;and&lt;/span&gt; you whant &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; catch the &lt;span class=&quot;hljs-keyword&quot;&gt;last&lt;/span&gt; occurrence. Otherwise &lt;span class=&quot;hljs-keyword&quot;&gt;no&lt;/span&gt; need &lt;span class=&quot;hljs-keyword&quot;&gt;to&lt;/span&gt; use it.
            Rem &lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; X &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; Clastath &lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt; Step &lt;span class=&quot;hljs-number&quot;&gt;-1&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&#39;(change if needed as per comment above)
            For X = 1 To Clastath
                If .Cells(1, X).Value = &quot;The Principals Book&quot; Then
                    Rem Old line, left only to show changes (.Value and .Value2)
                    Rem Ath.Range(&quot;D2: D&quot; &amp;amp; lastath).Value = Ath.Range(Ath.Cells(2, X), Ath.Cells(lastath, X)).Value2
                    Ath.Range(&quot;D2: D&quot; &amp;amp; lastath).Value = Ath.Range(Ath.Cells(2, X), Ath.Cells(lastath, X)).Value2
                    .Columns(4).Value = .Columns(1).Offset(0, X - 1).Value2
                    Exit For    &#39;&lt;/span&gt;Exit For...Next after achieving its goal

    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt; If: Next: &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;: &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;

    Ath.Activate &lt;span class=&quot;hljs-string&quot;&gt;&#39;Only used to show\move to the worksheet updated

End Sub
&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_13&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_4&quot;&gt;Solution 4:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Your code deserves several comments. To begin with, you have to solve your problem (see point 1).
In addition, several points can reduce the chances of error upon modification, and improve efficiency.&lt;/p&gt;&lt;ol&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Use other methods for copying &lt;code&gt;Range&lt;/code&gt;s&lt;/strong&gt;.
You have to specify what you want to copy (data, formulas, number formats, etc.) to decide which method to use.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;p&gt;Copy only data.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_15&quot; class=&quot;hljs language-bash&quot;&gt;Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).Value2 = Ath.Range(Ath.Cells(2, x), Ath.Cells(lastath, x)).Value2
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_15&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;or&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_16&quot; class=&quot;hljs language-scss&quot;&gt;Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Cells&lt;/span&gt;(lastath, x))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Copy&lt;/span&gt;
Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(&quot;D2:D&quot; &amp;amp; lastath)&lt;span class=&quot;hljs-selector-class&quot;&gt;.PasteSpecial&lt;/span&gt; xlPasteValues
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_16&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Copy (part or all of) number formats. See &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/questions/17359835/what-is-the-difference-between-text-value-and-value2&quot;&gt;this&lt;/a&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_17&quot; class=&quot;hljs language-bash&quot;&gt;Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).Value = Ath.Range(Ath.Cells(2, x), Ath.Cells(lastath, x)).Value
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_17&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;or&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_18&quot; class=&quot;hljs language-scss&quot;&gt;Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Cells&lt;/span&gt;(lastath, x))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Copy&lt;/span&gt;
Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(&quot;D2:D&quot; &amp;amp; lastath)&lt;span class=&quot;hljs-selector-class&quot;&gt;.PasteSpecial&lt;/span&gt; xlPasteValuesAndNumberFormats
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_18&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Copy formulas.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_19&quot; class=&quot;hljs language-rust&quot;&gt;Ath.&lt;span class=&quot;hljs-title function_ invoke__&quot;&gt;Range&lt;/span&gt;(Ath.&lt;span class=&quot;hljs-title function_ invoke__&quot;&gt;Cells&lt;/span&gt;(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath.&lt;span class=&quot;hljs-title function_ invoke__&quot;&gt;Cells&lt;/span&gt;(lastath, x)).&lt;span class=&quot;hljs-built_in&quot;&gt;Copy&lt;/span&gt;
Ath.&lt;span class=&quot;hljs-title function_ invoke__&quot;&gt;Range&lt;/span&gt;(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).PasteSpecial xlPasteFormulas  &#39; or xlPasteFormulasAndNumberFormats
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_19&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;Copy all.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_20&quot; class=&quot;hljs language-scss&quot;&gt;Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Cells&lt;/span&gt;(lastath, x))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Copy&lt;/span&gt;
Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(&quot;D2:D&quot; &amp;amp; lastath)&lt;span class=&quot;hljs-selector-class&quot;&gt;.PasteSpecial&lt;/span&gt; xlPasteAll
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_20&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;or&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_21&quot; class=&quot;hljs language-scss&quot;&gt;Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Cells&lt;/span&gt;(lastath, x))&lt;span class=&quot;hljs-selector-class&quot;&gt;.Copy&lt;/span&gt; Destination:=Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_21&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Fully qualify your &lt;code&gt;Range&lt;/code&gt;s&lt;/strong&gt;.
This issue shows up once and again (e.g., &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://stackoverflow.com/a/20605401/2707864&quot;&gt;this&lt;/a&gt;).
&lt;em&gt;What does this mean?&lt;/em&gt; Do not use &lt;code&gt;Cells&lt;/code&gt;, &lt;code&gt;Range&lt;/code&gt;, &lt;code&gt;Rows&lt;/code&gt; or &lt;code&gt;Columns&lt;/code&gt; without specifying which &lt;code&gt;Worksheet&lt;/code&gt; they belong to, unless you specifically want to do that (and even in that case, explicitly using &lt;code&gt;ActiveSheet&lt;/code&gt; improves readability and reduces the chances of errors, similar to using &lt;code&gt;Option Explicit&lt;/code&gt;).
For instance,&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_30&quot; class=&quot;hljs language-ini&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;lastath&lt;/span&gt; = Ath.Cells(Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt;).End(xlUp).Row
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_30&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;will take &lt;code&gt;Rows.Count&lt;/code&gt; from the &lt;code&gt;ActiveSheet&lt;/code&gt;, which might not be &lt;code&gt;Ath&lt;/code&gt;. You likely do not want that.
The correct form is&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_34&quot; class=&quot;hljs language-ini&quot;&gt;&lt;span class=&quot;hljs-attr&quot;&gt;lastath&lt;/span&gt; = Ath.Cells(Ath.Rows.Count, &lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt;).End(xlUp).Row
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_34&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Fix all other code.
&lt;em&gt;Note&lt;/em&gt;: in this case, code continues execution and the mistake may go unnoticed, as it produces a valid result. In other cases, code without fully qualified &lt;code&gt;Range&lt;/code&gt;s will throw an error (e.g., with something like &lt;code&gt;sheet1.Range(Cells(...&lt;/code&gt;, when &lt;code&gt;sheet1&lt;/code&gt; is not the &lt;code&gt;ActiveSheet&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;Your code seems inefficient&lt;/strong&gt;.
You might be copying data many times into the same &lt;code&gt;Range&lt;/code&gt;. It is better to find the leftmost cell in row 1, containing &lt;code&gt;&quot;The Principals Book&quot;&lt;/code&gt;, and copy the range for that column into &lt;code&gt;Range(&quot;D2:D&quot; &amp;amp; lastath)&lt;/code&gt;. Use&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_42&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; x &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; x = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt; Clastath
    &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, x) = &lt;span class=&quot;hljs-string&quot;&gt;&quot;The Principals Book&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).Value2 = Ath.Range(Ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x), Ath.Cells(lastath, x)).Value2   &lt;span class=&quot;hljs-comment&quot;&gt;&#39; or alternatives above&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_42&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;It is not clear in which &lt;code&gt;Worksheet&lt;/code&gt; you want columns inserted&lt;/strong&gt;.
It seems to be &lt;code&gt;Ath&lt;/code&gt;. The other &lt;code&gt;Worksheet&lt;/code&gt; is not used.&lt;/p&gt;&lt;/li&gt;&lt;li&gt;&lt;p&gt;&lt;strong&gt;You can insert many columns at once. You can also enter data into a range at once&lt;/strong&gt;.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_46&quot; class=&quot;hljs language-go&quot;&gt;Ath.Columns(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A:D&quot;&lt;/span&gt;).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
Ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:D1&quot;&lt;/span&gt;).Value = Array(&lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 2&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 3&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;EDITED 4&quot;&lt;/span&gt;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_46&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/li&gt;&lt;/ol&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_5&quot;&gt;Solution 5:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;1.Remove the space in your string address:
Before:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_47&quot; class=&quot;hljs language-bash&quot;&gt;ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2: D&quot;&lt;/span&gt; &amp;amp; lastath))
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_47&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;After:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_48&quot; class=&quot;hljs language-bash&quot;&gt;ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath))
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_48&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;2a. If you only want to copy the values, then use .value at the end of your range references:
Before:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_49&quot; class=&quot;hljs language-bash&quot;&gt;ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).value = ath.Range(ath.Cells(2, x), ath.Cells(lastath, x)) 
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_49&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;After:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_50&quot; class=&quot;hljs language-bash&quot;&gt;ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).value = ath.Range(ath.Cells(2, x).value, ath.Cells(lastath, x).value).value
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_50&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;2b. If you want values and formats then use .copy (destination):
Before:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_51&quot; class=&quot;hljs language-bash&quot;&gt;ath.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;D2:D&quot;&lt;/span&gt; &amp;amp; lastath).value = ath.Range(ath.Cells(2, x), ath.Cells(lastath, x)) 
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_51&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;After:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_52&quot; class=&quot;hljs language-scss&quot;&gt;ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Range&lt;/span&gt;(&quot;D2:D&quot; &amp;amp; lastath)&lt;span class=&quot;hljs-selector-class&quot;&gt;.copy&lt;/span&gt;(ath.Range(ath.Cells(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;, x)&lt;span class=&quot;hljs-selector-class&quot;&gt;.value&lt;/span&gt;, ath&lt;span class=&quot;hljs-selector-class&quot;&gt;.Cells&lt;/span&gt;(lastath, x)&lt;span class=&quot;hljs-selector-class&quot;&gt;.value&lt;/span&gt;))
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_52&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Also, you should always reference the worksheet of a references range (e.g. &lt;code&gt;ws.range(&quot;A1&quot;).value&lt;/code&gt;). You might also consider using a worksheet&#39;s .codename rather then .name if this isn&#39;t just a quick an dirty project.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/6243335809795719920/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/copying-variable-based-range-of-cells.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6243335809795719920'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6243335809795719920'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/copying-variable-based-range-of-cells.html' title='Copying A Variable Based Range Of Cells To Another Range'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-1421122276162283649</id><published>2023-10-06T19:58:00.001-07:00</published><updated>2023-10-06T19:58:19.691-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>How To Copy Specific Range Cells From Multiple Sheets To One Sheet?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a master workbook in one folder and 100+ child workbooks in a different folder. Every week I need to copy a specific range of cells from the child workbooks (sheet name is s&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I fully agree with guys who told you that none will write the code for you, but you are lucky that I have that already written and there may be other people looking for same info, so here it is.
Put the code to module in your master workbook and replace some data as commented:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Option&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Explicit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; GoThroughFilesAndCopyData()

&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; BrowseFolder &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; FileItem &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; oFolder &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; FSO &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; shtWork &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; lngRow &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; i &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;: i = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; strPath &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; MasterSheet &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; ChildSheet &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet

Application.ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39; selecting the folder to look files in&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Application.FileDialog(msoFileDialogFolderPicker)
        .Title = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Select the folder with child workbooks&quot;&lt;/span&gt;
        .Show
        &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Resume&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
        Err.Clear
        BrowseFolder = .SelectedItems(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)
        &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Err.Number &amp;lt;&amp;gt; &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
            MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;You didn&#39;t select anything!&quot;&lt;/span&gt;
            Application.ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; FSO = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Scripting.FileSystemObject&quot;&lt;/span&gt;) &lt;span class=&quot;hljs-comment&quot;&gt;&#39; creating filesystem object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; oFolder = FSO.getfolder(BrowseFolder) &lt;span class=&quot;hljs-comment&quot;&gt;&#39; creating folder object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; MasterSheet = ThisWorkbook.Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;masterworksheet_name&quot;&lt;/span&gt;) &lt;span class=&quot;hljs-comment&quot;&gt;&#39;replace masterworksheet_name with the name of your worksheet in master workbook&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; FileItem &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; oFolder.Files &lt;span class=&quot;hljs-comment&quot;&gt;&#39;looking through each file&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; UCase(FileItem.Name) &lt;span class=&quot;hljs-built_in&quot;&gt;Like&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;*.XLS*&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;try open only excel files&lt;/span&gt;

            i = MasterSheet.Cells(Rows.Count, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;).&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;(xlUp).row + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39; find last not empty row and get a next one which is empty&lt;/span&gt;
            Workbooks.Open (BrowseFolder &amp;amp; Application.PathSeparator &amp;amp; FileItem.Name)
            &lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; ChildSheet = Workbooks(FileItem.Name).Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;worksheet_name&quot;&lt;/span&gt;) &lt;span class=&quot;hljs-comment&quot;&gt;&#39;worksheet_name - replace with child sheet name&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; ChildSheet &lt;span class=&quot;hljs-comment&quot;&gt;&#39; replace your_range_to_copy with the range on a child sheet you want to copy&lt;/span&gt;
                Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;your_range_to_copy&quot;&lt;/span&gt;).Copy Destination:=MasterSheet.Cells(i, column_number) &lt;span class=&quot;hljs-comment&quot;&gt;&#39;i - is the number of last empty row, replace column_number - must be the column number of range to insert&lt;/span&gt;
                .Parent.Close SaveChanges:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;close child workbook without saving&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;

    Application.ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This will do what you want.&lt;/p&gt;&lt;p&gt;Copy a range of each sheet&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;Note: This example use the function LastRow&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-sql&quot;&gt;This example &lt;span class=&quot;hljs-keyword&quot;&gt;copy&lt;/span&gt; the &lt;span class=&quot;hljs-keyword&quot;&gt;range&lt;/span&gt; A1:G1 &lt;span class=&quot;hljs-keyword&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;each&lt;/span&gt; worksheet.
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Change the range in this code line&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Fill in the range that you want to copy&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Set CopyRng = sh.Range(&quot;A1:G1&quot;)&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; CopyRangeFromMultiWorksheets()
    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; sh &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet
    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; DestSh &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet
    &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; Last &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; CopyRng &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range

    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Application
        .ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
        .EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Delete the sheet &quot;RDBMergeSheet&quot; if it exist&lt;/span&gt;
    Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Resume&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
    ActiveWorkbook.Worksheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;RDBMergeSheet&quot;&lt;/span&gt;).Delete
    &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;
    Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Add a worksheet with the name &quot;RDBMergeSheet&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; DestSh = ActiveWorkbook.Worksheets.Add
    DestSh.Name = &lt;span class=&quot;hljs-string&quot;&gt;&quot;RDBMergeSheet&quot;&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;loop through all worksheets and copy the data to the DestSh&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; sh &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; ActiveWorkbook.Worksheets
        &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; sh.Name &amp;lt;&amp;gt; DestSh.Name &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Find the last row with data on the DestSh&lt;/span&gt;
            Last = LastRow(DestSh)

            &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Fill in the range that you want to copy&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; CopyRng = sh.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1:G1&quot;&lt;/span&gt;)

            &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Test if there enough rows in the DestSh to copy all the data&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; Last + CopyRng.Rows.Count &amp;gt; DestSh.Rows.Count &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
                MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;There are not enough rows in the Destsh&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt; ExitTheSub
            &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;This example copies values/formats, if you only want to copy the&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;values or want to copy everything look at the example below this macro&lt;/span&gt;
            CopyRng.Copy
            &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; DestSh.Cells(Last + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt;)
                .PasteSpecial xlPasteValues
                .PasteSpecial xlPasteFormats
                Application.CutCopyMode = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Optional: This will copy the sheet name in the H column&lt;/span&gt;
            DestSh.Cells(Last + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-string&quot;&gt;&quot;H&quot;&lt;/span&gt;).Resize(CopyRng.Rows.Count).Value = sh.Name

        &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;&lt;span class=&quot;hljs-symbol&quot;&gt;ExitTheSub:&lt;/span&gt;

    Application.&lt;span class=&quot;hljs-keyword&quot;&gt;Goto&lt;/span&gt; DestSh.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)

    &lt;span class=&quot;hljs-comment&quot;&gt;&#39;AutoFit the column width in the DestSh sheet&lt;/span&gt;
    DestSh.Columns.AutoFit

    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Application
        .ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;
        .EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Also . . .&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Common Functions required for all routines&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; LastRow(sh &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet)
    &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Resume&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
    LastRow = sh.Cells.Find(What:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;*&quot;&lt;/span&gt;, _
                            After:=sh.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1&quot;&lt;/span&gt;), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByRows, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;).Row
    &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; LastCol(sh &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Worksheet)
    &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Resume&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
    LastCol = sh.Cells.Find(What:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;*&quot;&lt;/span&gt;, _
                            After:=sh.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1&quot;&lt;/span&gt;), _
                            Lookat:=xlPart, _
                            LookIn:=xlFormulas, _
                            SearchOrder:=xlByColumns, _
                            SearchDirection:=xlPrevious, _
                            MatchCase:=&lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;).Column
    &lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/1421122276162283649/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-copy-specific-range-cells-from.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1421122276162283649'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1421122276162283649'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-copy-specific-range-cells-from.html' title='How To Copy Specific Range Cells From Multiple Sheets To One Sheet?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-3611073333916246985</id><published>2023-10-06T17:48:00.001-07:00</published><updated>2023-10-06T17:48:16.198-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Adodb"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Invalid Sql Statement Expected; ‘delete’,’insert’,</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I have a code  Dim Cn As New ADODB.Connection  Dim cmd As ADODB.Command Set cmd = New ADODB.Command Dim i As Long  Cn.ConnectionString = &#39;Provider=Microsoft.Jet.OLEDB.4.0;&#39; &amp; _&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The syntax for your parametered query doesn&#39;t look right.&lt;/p&gt;&lt;blockquote&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;DECLARE&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@TS&lt;/span&gt;_HD &lt;span class=&quot;hljs-keyword&quot;&gt;DOUBLE&lt;/span&gt;;
&lt;span class=&quot;hljs-keyword&quot;&gt;SET&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@TS&lt;/span&gt;_HD &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; ?TS_HD;
&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
     So_HD
    ,Ngay_HD
    ,Ten_Khach_Hang
    ,Ma_So_Thue
    ,&lt;span class=&quot;hljs-built_in&quot;&gt;SUM&lt;/span&gt;(Doanh_So_KT) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; DoanhSo
    ,&lt;span class=&quot;hljs-built_in&quot;&gt;SUM&lt;/span&gt;(Thue_VAT) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; VAT 
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; [BR$]
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; Ngay_HD &lt;span class=&quot;hljs-operator&quot;&gt;&amp;lt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;AND&lt;/span&gt; TS_HD &lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;@TS&lt;/span&gt;_HD 
&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; 
     So_HD
    ,Ma_So_Thue
    ,Ngay_HD
    ,Ten_Khach_Hang
&lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; 
     Ngay_HD
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/blockquote&gt;&lt;p&gt;I&#39;m not sure the provider supports &lt;code&gt;DECLARE&lt;/code&gt; statements. If it doesn&#39;t, that&#39;s why you&#39;re getting this message. Let&#39;s try to remove it:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;SELECT&lt;/span&gt; 
     So_HD
    ,Ngay_HD
    ,Ten_Khach_Hang
    ,Ma_So_Thue
    ,SUM(Doanh_So_KT) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; DoanhSo
    ,SUM(Thue_VAT) &lt;span class=&quot;hljs-keyword&quot;&gt;AS&lt;/span&gt; VAT 
&lt;span class=&quot;hljs-keyword&quot;&gt;FROM&lt;/span&gt; [BR$]
&lt;span class=&quot;hljs-keyword&quot;&gt;WHERE&lt;/span&gt; Ngay_HD &amp;lt;&amp;gt; NULL &lt;span class=&quot;hljs-built_in&quot;&gt;AND&lt;/span&gt; TS_HD = ?
&lt;span class=&quot;hljs-keyword&quot;&gt;GROUP&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; 
     So_HD
    ,Ma_So_Thue
    ,Ngay_HD
    ,Ten_Khach_Hang
&lt;span class=&quot;hljs-keyword&quot;&gt;ORDER&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;BY&lt;/span&gt; 
     Ngay_HD
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Notice the WHERE clause, &lt;code&gt;WHERE Ngay_HD &amp;lt;&amp;gt; NULL AND TS_HD = ?&lt;/code&gt; - the parameter placeholder is just a question mark.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;I&#39;m pretty sure that statement would work.&lt;/p&gt;&lt;p&gt;I&#39;m less sure about how the parameter is passed in though:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-java&quot;&gt;&lt;span class=&quot;hljs-type&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;TS_HD&lt;/span&gt;&lt;span class=&quot;hljs-operator&quot;&gt;=&lt;/span&gt; cmd.CreateParameter(&lt;span class=&quot;hljs-string&quot;&gt;&quot;?TS_HD&quot;&lt;/span&gt;, adDouble, adParamInput)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I think you can drop the name parameter, it&#39;s optional - and some providers don&#39;t support named parameters. That sucks though, because now you need to &lt;em&gt;name the arguments&lt;/em&gt; since the &lt;code&gt;Name&lt;/code&gt; parameter is first in the signature of &lt;code&gt;CreateParameter&lt;/code&gt;:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_7&quot; class=&quot;hljs language-go&quot;&gt;Set TS_HD = cmd.CreateParameter(Type:=adDouble, Direction:=adParamInput)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_7&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;An alternative could be to &lt;code&gt;New&lt;/code&gt; it up and initialize it &quot;manually&quot;:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_9&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; param &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;New&lt;/span&gt; ADODB.Parameter
&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; param
    .Type = adDouble
    .Direction = adParamInput
    .Value = &lt;span class=&quot;hljs-number&quot;&gt;0.01&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;in excel this value is 10% &#39;?? really? it&#39;s 1% here!&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;

cmd.Parameters.Append param
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_9&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/3611073333916246985/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/invalid-sql-statement-expected.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3611073333916246985'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3611073333916246985'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/invalid-sql-statement-expected.html' title='Invalid Sql Statement Expected; ‘delete’,’insert’,'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-6134286215911518365</id><published>2023-10-06T16:16:00.001-07:00</published><updated>2023-10-06T16:16:28.974-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Change Link In Workbook Programmatically</title><content type='html'>&lt;div class=&quot;question&quot;&gt;All, I have the following code to change a workbook&#39;s link. ThisWorkbook.ChangeLink &#39;OldPath.xlsx&#39;, &#39;NewPath.xlsx&#39;, xlLinkTypeExcelLinks My problem is that &#39;NewPath.xlsx&#39; represent&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;The only idea I have is a extended version of @d-stroyer solution. You need to replace part of the formulas including path to the document as well (or simply workbook reference if one is open):&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-go&quot;&gt;Cells.Replace What:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;C:\Users\Name\Desktop\[OldPath.xlsx]OldSheetName&quot;&lt;/span&gt;, _
    Replacement:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;C:\Users\Name\Desktop\[NewPath.xlsx]NewSheetName&quot;&lt;/span&gt;, LookAt:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Unfortunately, this will not work (I think, not tested) if you want to replace links in other excel elements like: series of charts, possibly data source of pivottables, etc.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Yes, there is. Use a simple Replace statement :&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-go&quot;&gt;Sub UpdateSheetName()

    Cells.Replace What:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;OldSheetName&quot;&lt;/span&gt;, Replacement:=&lt;span class=&quot;hljs-string&quot;&gt;&quot;NewSheetName&quot;&lt;/span&gt;, LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
End Sub
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;If your workbook has other occurrences of the sheet name, and you don&#39;t want them to be caught by the search, use a limited range. Also, you can restrict by searching &quot;OldSheetName!&quot; (with the &quot;!&quot;) and replacing by &quot;NewSheetName!&quot;.&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/6134286215911518365/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/change-link-in-workbook-programmatically.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6134286215911518365'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/6134286215911518365'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/change-link-in-workbook-programmatically.html' title='Change Link In Workbook Programmatically'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-835125318964135121</id><published>2023-10-06T15:52:00.001-07:00</published><updated>2023-10-06T15:52:33.917-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Select Column In A Selected Range Vba</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I&#39;m trying to filter my table and copy just a column in my filtered range at a time. I tried to get column 2 in my range but it returns only the first cell. I also tried .entireCol&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Your selectedRange is a multiple area selection - in this instance, the columns property returns columns from only the first area of the range.&lt;/p&gt;&lt;p&gt;Instead, use the intersection of your selectedRange and the entirecolumn your are interested in - for instance with&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-scss&quot;&gt;Application&lt;span class=&quot;hljs-selector-class&quot;&gt;.Intersect&lt;/span&gt;(selectedRange.columns(&lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;)&lt;span class=&quot;hljs-selector-class&quot;&gt;.Entirecolumn&lt;/span&gt;,selectedRange)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/835125318964135121/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/select-column-in-selected-range-vba.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/835125318964135121'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/835125318964135121'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/select-column-in-selected-range-vba.html' title='Select Column In A Selected Range Vba'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-1026700534168460100</id><published>2023-10-06T13:49:00.001-07:00</published><updated>2023-10-06T13:49:36.003-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Openpyxl"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><title type='text'>Reading Cell Value With Applied Number Format Openpyxl? - Redux</title><content type='html'>&lt;div class=&quot;question&quot;&gt;Python 2.7, openpyxl 2.4.x I&#39;m trying to read a cell that is a date value (&#39;05/01/2016&#39;) in excel and has custom number formatting applied (&#39;yyyymm&#39;) so it displays as &#39;201605&#39;. Wh&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;It&#39;s not implemented.
What you are looking for is cell.number_format.
Try the following:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-python&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;hljs-title function_&quot;&gt;pyDateFormat&lt;/span&gt;(&lt;span class=&quot;hljs-params&quot;&gt;nf&lt;/span&gt;):
  &lt;span class=&quot;hljs-keyword&quot;&gt;import&lt;/span&gt; re
  &lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&quot;Convert xlsx cell.number_format to Python date Format.&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;#xlsx Format   = &#39;YYYYMMDD&#39;, &#39;YYYY\\-MM\\-DD&#39;&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;#Python Format = &#39;%Y%m%d&#39;&lt;/span&gt;
  nf = re.sub(&lt;span class=&quot;hljs-string&quot;&gt;r&#39;\\&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;r&#39;&#39;&lt;/span&gt;,nf,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,re.IGNORECASE) &lt;span class=&quot;hljs-comment&quot;&gt;#Remove Escapes&lt;/span&gt;
  nf = re.sub(&lt;span class=&quot;hljs-string&quot;&gt;r&#39;([^Y]*)(Y+)(.*)&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;r&#39;\1%Y\3&#39;&lt;/span&gt;,nf,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,re.IGNORECASE) &lt;span class=&quot;hljs-comment&quot;&gt;#Change YYYY to %Y&lt;/span&gt;
  nf = re.sub(&lt;span class=&quot;hljs-string&quot;&gt;r&#39;([^M]*)(M+)(.*)&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;r&#39;\1%m\3&#39;&lt;/span&gt;,nf,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,re.IGNORECASE) &lt;span class=&quot;hljs-comment&quot;&gt;#Change MM to %m&lt;/span&gt;
  nf = re.sub(&lt;span class=&quot;hljs-string&quot;&gt;r&#39;([^D]*)(D+)(.*)&#39;&lt;/span&gt;,&lt;span class=&quot;hljs-string&quot;&gt;r&#39;\1%d\3&#39;&lt;/span&gt;,nf,&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;,re.IGNORECASE) &lt;span class=&quot;hljs-comment&quot;&gt;#Change DD to %d&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;return&lt;/span&gt; nf
&lt;span class=&quot;hljs-comment&quot;&gt;#end def pyDateFormat&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;At the point you need the formated cell.value do:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-lua&quot;&gt;  cell = wb.ws[&lt;span class=&quot;hljs-string&quot;&gt;&#39;A1&#39;&lt;/span&gt;]
  &lt;span class=&quot;hljs-keyword&quot;&gt;if&lt;/span&gt; cell.is_date:
    value = cell.value.&lt;span class=&quot;hljs-built_in&quot;&gt;date&lt;/span&gt;().__format__( pyDateFormat(cell.number_format) )
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;&lt;em&gt;Tested with Python: 3.4.2 - openpyxl: 2.4.1 - LibreOffice: 4.3.3.2&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/1026700534168460100/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/reading-cell-value-with-applied-number.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1026700534168460100'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1026700534168460100'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/reading-cell-value-with-applied-number.html' title='Reading Cell Value With Applied Number Format Openpyxl? - Redux'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-651224178741299430</id><published>2023-10-06T12:53:00.001-07:00</published><updated>2023-10-06T12:53:16.701-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Recursion"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Recursion Code In Vba</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am trying to run this code to calculate Q(n) at different Tn in the Equation 16.4 in the attached picture.But its not giving me the correct output. I would appreciate any help.&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;To solve a recursive function you can write it this way, for example&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; Factorial(n &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;long&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; n = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        Factorial = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
        Factorial = n * Factorial(n-&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Yes, you can see &lt;code&gt;For...Loop&lt;/code&gt; can also do the Factorial calculation, but in your case, its much easier to use recursive solution.&lt;/p&gt;&lt;p&gt;Besides Eq 16.4 is intentionally written as a recursive function. It is not written as a summation function because it is harder to do so. If given to you is a summation function, then you can apply the &lt;code&gt;For...Loop&lt;/code&gt; solution.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;Hope this helps.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;EDIT&lt;/strong&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; Q(n &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;long&lt;/span&gt;) &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;double&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; n = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        Q = &lt;span class=&quot;hljs-number&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
        Q = Z * ( L * Q_t - (L + d * S) * Q(n-&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;) ) / ( Z * ( L + d * S ) )
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Notice that the function &lt;code&gt;Q&lt;/code&gt; keep calling itself in &lt;code&gt;Q(n-1)&lt;/code&gt; when &lt;code&gt;n&amp;gt;1&lt;/code&gt;. That is called recursive solution.&lt;/p&gt;&lt;p&gt;(Check the formula. I might copy it wrong)&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/651224178741299430/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/recursion-code-in-vba.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/651224178741299430'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/651224178741299430'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/recursion-code-in-vba.html' title='Recursion Code In Vba'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-2991803878874113638</id><published>2023-10-06T11:58:00.001-07:00</published><updated>2023-10-06T11:58:51.500-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Updating Value Of The Target Cell In Excel Vba</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am trying to update the value of the Target cell using VBA macro when it exists in particular Range.  I want to update its value as by concatenating a string to its value. For ex&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Disable events prior to making any change that will fire the &lt;code&gt;Change&lt;/code&gt; event:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; oldCellAddress &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; oldCellValue &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Private&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Worksheet_Change(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; Target &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range)
    oldCellValue = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Not&lt;/span&gt; Intersect(Target, Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;E10:E500&quot;&lt;/span&gt;)) &lt;span class=&quot;hljs-built_in&quot;&gt;Is&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
        oldCellValue = Target.Value
        Target.Value = &lt;span class=&quot;hljs-string&quot;&gt;&quot;AST-&quot;&lt;/span&gt; &amp;amp; oldCellValue
        Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;If events aren&#39;t disabled, your change to the cell will fire the &lt;code&gt;Worksheet_Change&lt;/code&gt; event, which will change the cell, which will fire the &lt;code&gt;Worksheet_Change&lt;/code&gt; event, which will change the cell, which will fire the &lt;code&gt;Worksheet_Change&lt;/code&gt; event, which will change the cell, which will fire the &lt;code&gt;Worksheet_Change&lt;/code&gt; event, which will change the cell, which will fire the ...&lt;/p&gt;&lt;hr&gt;&lt;p&gt;Assuming you don&#39;t need your &lt;code&gt;oldCellValue&lt;/code&gt; and &lt;code&gt;oldCellAddress&lt;/code&gt; module-scope variables, but do want to handle changes to multiple cells, use this instead:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_8&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Private&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Worksheet_Change(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; Target &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range)
    &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Not&lt;/span&gt; Intersect(Target, Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;E10:E500&quot;&lt;/span&gt;)) &lt;span class=&quot;hljs-built_in&quot;&gt;Is&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; c &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range
        Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; c &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; Intersect(Target, Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;E10:E500&quot;&lt;/span&gt;)).Cells
            c.Value = &lt;span class=&quot;hljs-string&quot;&gt;&quot;AST-&quot;&lt;/span&gt; &amp;amp; c.Value
        &lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
        Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_8&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/2991803878874113638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/updating-value-of-target-cell-in-excel.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2991803878874113638'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2991803878874113638'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/updating-value-of-target-cell-in-excel.html' title='Updating Value Of The Target Cell In Excel Vba'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-5553631317969050541</id><published>2023-10-06T11:26:00.001-07:00</published><updated>2023-10-06T11:26:47.114-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Python"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><category scheme="http://www.blogger.com/atom/ns#" term="Xlwings"/><title type='text'>How To Wait For Xlwings To Complete Python Code In Vba?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am calling RunPython in VBA from the xlwings module with the following code: Sub Portfolio_Optimze() RunPython (&#39;import quotes; quotes.get_quote()&#39;) SolverAdd CellRef:=&#39;$H$18:$H$&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Some info to start with: Excel on Mac only allows external processes to write to the cells when Excel is idle, i.e. while no Macros are running. That&#39;s why the &lt;code&gt;RunPython&lt;/code&gt; call on Mac runs as background process that only really kicks in when the calling macro is finished running.&lt;/p&gt;&lt;p&gt;I would suggest one of the two following solutions:&lt;/p&gt;&lt;p&gt;1) Program the solver part in Python, too, for example using &lt;code&gt;scipy.optimize&lt;/code&gt;.&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;2) Put the solver VBA into its own Sub and call it from Python. This is currently a planned feature for the next version of xlwings, see &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://github.com/ZoomerAnalytics/xlwings/issues/134&quot;&gt;here&lt;/a&gt;, but you can work around for now like so (assuming &lt;code&gt;wb&lt;/code&gt; is your Workbook):&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-bash&quot;&gt;app = xlwings.Application(wkb=wb)
app.xl_app.run_VB_macro(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SolverMacro&#39;&lt;/span&gt;)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;UPDATE&lt;/strong&gt;, since v0.7.1 this is now properly supported:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_4&quot; class=&quot;hljs language-python-repl&quot;&gt;&lt;span class=&quot;hljs-meta&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;language-python&quot;&gt;solver_macro = wb.macro(&lt;span class=&quot;hljs-string&quot;&gt;&#39;SolverMacro&#39;&lt;/span&gt;)&lt;/span&gt;&lt;span class=&quot;hljs-meta&quot;&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;language-python&quot;&gt;solver_macro()&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_4&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Another approach is to change a value in a hidden sheet at the end of your python code and with a &lt;code&gt;Worksheet_Change&lt;/code&gt; snippet which will fire off some vba code. If hidden sheet is &quot;Supplement&quot; then add something like this in end of python code:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Range(&#39;Supplement&#39;, &#39;A1&#39;).value = Range(&#39;Supplement&#39;, &#39;A1&#39;).value +1&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;And the vba in the &quot;Supplement&quot; sheet could be:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;Private Sub Worksheet_Change(ByVal Target As Range)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;If Not Intersect(Target, Me.Range(&quot;A1&quot;)) Is Nothing Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Worksheets(&quot;Main1&quot;).Range(&quot;A1&quot;).WrapText = True&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;End If
End Sub&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Remember that &lt;code&gt;Application.EnableEvents&lt;/code&gt; needs to be &lt;code&gt;= True&lt;/code&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;A bit clunky, maybe, but also look at &lt;code&gt;Application.OnTime&lt;/code&gt; method which lets you schedule code to run at a set time. So put your solver code into another proc, call &lt;code&gt;RunPython&lt;/code&gt; and then schedule the solver proc for, say, 10 seconds time.&lt;/p&gt;&lt;p&gt;Or, possibly a better answer, get the python code to either write to a &lt;code&gt;Range&lt;/code&gt; or text file when done. The proc with solver code will look at the range or the file to see if python is done. If python not finished then schedules itself to run again in N secs, otherwise runs the solver.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/5553631317969050541/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-wait-for-xlwings-to-complete.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/5553631317969050541'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/5553631317969050541'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-wait-for-xlwings-to-complete.html' title='How To Wait For Xlwings To Complete Python Code In Vba?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-2863852815127074165</id><published>2023-10-06T10:25:00.001-07:00</published><updated>2023-10-06T10:25:17.508-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Excel Vba: Can We Refer A Column By Its Name?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I want to refer a column by its header name.  Currently column is 4th one and header name is &#39;Preference&#39;.  And the column consists of &#39;Yes&#39; or &#39;No&#39; 5th column header is &#39;Reason&#39; A&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Further to my comments, if you want to do it direct, you would have to do this:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-sql&quot;&gt;cells(i,Application.WorksheetFunction.Match(&quot;Preference&quot;, &lt;span class=&quot;hljs-keyword&quot;&gt;Range&lt;/span&gt;(&quot;1:1&quot;), &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)).
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Here is a function to find the column for X instance. I have put a subroutine in there to call it as an example for you.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; ColInstanceExample()
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; MyColInstance &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;
MyColInstance = ColInstance(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Preference&quot;&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;2&lt;/span&gt;) &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Pass in what you are searching for and the instance you want to return the column number for&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; MyColInstance = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
    MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;Not Found&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
    MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;Found at column: &quot;&lt;/span&gt; &amp;amp; MyColInstance
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; ColInstance(HeadingString &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;, InstanceNum &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; ColNum &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Resume&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
ColNum = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt; X = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;To&lt;/span&gt; InstanceNum
    ColNum = (Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1&quot;&lt;/span&gt;).Offset(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, ColNum).column) + Application.WorksheetFunction.Match(HeadingString, Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A1&quot;&lt;/span&gt;).Offset(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;, ColNum + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;).Resize(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, Columns.Count - (ColNum + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)), &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
ColInstance = ColNum
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/2863852815127074165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-can-we-refer-column-by-its.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2863852815127074165'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2863852815127074165'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-can-we-refer-column-by-its.html' title='Excel Vba: Can We Refer A Column By Its Name?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-4791960350922846399</id><published>2023-10-06T09:21:00.001-07:00</published><updated>2023-10-06T09:21:02.272-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Wait For Csv File To Open?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am trying to download and open a CSV file using VBA in Excel. When I step through using the debugger my code works fine but when I try to run it normally it won&#39;t work, it is try&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Usually such behavior happens not because of the code logic but because of interrupts. Depending on the nature of your environment it could be one of two things&lt;/p&gt;&lt;ul&gt;&lt;li&gt;some background refreshing process is getting executed sometime in between your code execution time causing some issues. e.g. in a financial services environment, your Bloomberg API could be doing its timely &lt;code&gt;BlpUpdate&lt;/code&gt; event&lt;/li&gt;&lt;li&gt;your code blocks up a large chunk of time and causes unexpected behavior because event which was triggered during your loop was blocked too long waiting for your code to complete on the main thread.&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;So you need to try the following two solutions, one of which should work&lt;/p&gt;&lt;p&gt;For the second problem, inside your&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;While&lt;/span&gt; Condition
&lt;span class=&quot;hljs-comment&quot;&gt;&#39; ... your code ...&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Loop&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;add a line of code that checks for and clears any pending Event queues, making it...&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;While&lt;/span&gt; Condition
DoEvents     &lt;span class=&quot;hljs-comment&quot;&gt;&#39; either put it at the start or at the end of your code&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39; ... your existing code ...&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Loop&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;This will give the system some &#39;breathing space&#39; to wrap up pending events. You&#39;ll need to experiment with the location of your &lt;code&gt;DoEvents&lt;/code&gt; code.&lt;/p&gt;&lt;p&gt;For the first problem, you can try enclosing your entire loop within an &lt;code&gt;Event Protected&lt;/code&gt; area of code, to ensure it finishes running before anything disturbs it.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_5&quot; class=&quot;hljs language-vbnet&quot;&gt;Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;your loop and other code comes here&lt;/span&gt;

Application.EnableEvents = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_5&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Once again, you might need a bit of trial and error to see how much of the code needs to be thrown into the Event-free zone before it works as expected.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/4791960350922846399/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/wait-for-csv-file-to-open.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4791960350922846399'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/4791960350922846399'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/wait-for-csv-file-to-open.html' title='Wait For Csv File To Open?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-2795077208060359474</id><published>2023-10-06T08:04:00.001-07:00</published><updated>2023-10-06T08:04:35.256-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><title type='text'>Calculating Slopes Of Fluorescence Over Time</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am a newbie to R and want to use it to make my life easier analyzing the data of my fluorescence assays.  Before I did the analysis manually in excel but now want to make it easi&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;here is a possible solution &lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-bash&quot;&gt;apply(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;[,2:ncol(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;)], 2, &lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt;(x){
  model = lm(x ~ &lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$time&lt;/span&gt; - 1)
  &lt;span class=&quot;hljs-built_in&quot;&gt;return&lt;/span&gt;(coef(model))
})
&lt;span class=&quot;hljs-comment&quot;&gt;#ouput &lt;/span&gt;
sample1 sample2 sample3 
4       3       2  
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;It assumes the intercept is 0. If you would like the intercept evaluated use:&lt;/p&gt;&lt;p&gt;&lt;code&gt;model = lm(x ~ df$time)&lt;/code&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;p&gt;What this code does is to &lt;code&gt;apply&lt;/code&gt; a function over columns (indicated by &lt;code&gt;2&lt;/code&gt;) of the data frame (&lt;code&gt;df&lt;/code&gt;). It takes all columns from the second till the last one (&lt;code&gt;[2:ncol(df]&lt;/code&gt;), and does a linear regression (&lt;code&gt;model = lm(x ~ df$time - 1&lt;/code&gt;) and returns the coefficient(s) (&lt;code&gt;return(coef(model)&lt;/code&gt;). &lt;/p&gt;&lt;p&gt;If the first column is not always named &lt;code&gt;time&lt;/code&gt; then: &lt;/p&gt;&lt;p&gt;&lt;code&gt;model = lm(x ~ df[,1] - 1)&lt;/code&gt;&lt;/p&gt;&lt;p&gt;to indicate the first column is the &lt;code&gt;x&lt;/code&gt;&lt;/p&gt;&lt;p&gt;EDIT: problem is the variables were not coded as numeric. Here is a solution:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_11&quot; class=&quot;hljs language-bash&quot;&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$Time&lt;/span&gt; = as.numeric(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$Time&lt;/span&gt;) &lt;span class=&quot;hljs-comment&quot;&gt;#convert time to numeric&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_11&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Without intercept:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_12&quot; class=&quot;hljs language-bash&quot;&gt;  apply(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;[,2:ncol(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;)], 2, &lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt;(x){
      x = as.numeric(x) &lt;span class=&quot;hljs-comment&quot;&gt;#convert x to numeric&lt;/span&gt;
      model = lm(x ~ &lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$Time&lt;/span&gt; - 1)
      &lt;span class=&quot;hljs-built_in&quot;&gt;return&lt;/span&gt;(coef(model))
    })
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_12&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;With intercept:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_13&quot; class=&quot;hljs language-bash&quot;&gt;apply(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;[,2:ncol(&lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;)], 2, &lt;span class=&quot;hljs-keyword&quot;&gt;function&lt;/span&gt;(x){
  x = as.numeric(x) &lt;span class=&quot;hljs-comment&quot;&gt;#convert x to numeric&lt;/span&gt;
  model = lm(x ~ &lt;span class=&quot;hljs-built_in&quot;&gt;df&lt;/span&gt;&lt;span class=&quot;hljs-variable&quot;&gt;$time&lt;/span&gt;)
  &lt;span class=&quot;hljs-built_in&quot;&gt;return&lt;/span&gt;(coef(model)[2])
})
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_13&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/2795077208060359474/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/calculating-slopes-of-fluorescence-over.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2795077208060359474'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/2795077208060359474'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/calculating-slopes-of-fluorescence-over.html' title='Calculating Slopes Of Fluorescence Over Time'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-7067173502990813126</id><published>2023-10-06T03:23:00.001-07:00</published><updated>2023-10-06T03:23:25.055-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Excel Vba Populate Listbox1 Based On Listbox2 Selection</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am trying to figure out the proper code for populating a listbox based on a selection from a second listbox. I will explain my question the best I can. I have one worksheet with&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;In the change event of the part number combobox do something like this.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; ws &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Excel.Worksheet
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; lRow &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; ws = Worksheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Sheet2&quot;&lt;/span&gt;)
lRow = &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Loop through the rows&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;While&lt;/span&gt; lRow &amp;lt;= ws.UsedRange.Rows.count
    &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Check if Column A has the value of the selected part number.&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; ws.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;A&quot;&lt;/span&gt; &amp;amp; lRow).Value = LstPartNum.&lt;span class=&quot;hljs-keyword&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
        UserForm1.LstLocation.Clear
        &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Load the locations&lt;/span&gt;
        UserForm1.LstLocation.List = Split(ws.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B&quot;&lt;/span&gt; &amp;amp; lRow).Value, &lt;span class=&quot;hljs-string&quot;&gt;&quot;,&quot;&lt;/span&gt;)
        &lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;
lRow = lRow + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Loop&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;If your UserForm1.LstPartNum.List = Split() does not work to load the list, here is code to loop the split array.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; szLocs() &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; i &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;integer&lt;/span&gt;

szLocs= Split(ws.Range(&lt;span class=&quot;hljs-string&quot;&gt;&quot;B&quot;&lt;/span&gt; &amp;amp; lRow).Value, &lt;span class=&quot;hljs-string&quot;&gt;&quot;,&quot;&lt;/span&gt;)

i = &lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Loop though each token&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Do&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;While&lt;/span&gt; i &amp;lt;= UBound(szPieces)
    UserForm1.LstPartNum.Additem szPieces(i)
i = i + &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Loop&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/7067173502990813126/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-populate-listbox1-based-on.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/7067173502990813126'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/7067173502990813126'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/excel-vba-populate-listbox1-based-on.html' title='Excel Vba Populate Listbox1 Based On Listbox2 Selection'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-7660862066851368281</id><published>2023-10-06T00:40:00.001-07:00</published><updated>2023-10-06T00:40:55.230-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term=".net"/><category scheme="http://www.blogger.com/atom/ns#" term="C#"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><title type='text'>Library To Write An Excel File</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am using Microsoft Excel Interop library for exporting Excel file. However, the limit of this library is that:  Require the user&#39;s computer must have Microsoft Excel. When write&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I have used &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://epplus.codeplex.com/&quot;&gt;EPPlus&lt;/a&gt; for .xlsx reading/writing and it has worked great&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I think the only way to achieve this without having Excel installed is to just write the file format directly. Microsoft documented the file format a few years ago. You can find them at &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/library/cc313118.aspx&quot;&gt;http://msdn.microsoft.com/en-us/library/cc313118.aspx&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;
I&#39;ve just found EPPlus. Check it out at &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://epplus.codeplex.com/&quot;&gt;http://epplus.codeplex.com/&lt;/a&gt;&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;You can use an ODBC or OLE connector to read and write an Excel file. However, I am not sure if you can create a file with it, you might need to keep a dummy-empty file with the correct layout. &lt;/p&gt;&lt;p&gt;Update: It is, accordingly to comment below from @Joel Gauvreau possible to create an excel file using this technique.&lt;/p&gt;&lt;p&gt;Links:
&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://support.microsoft.com/kb/257819&quot;&gt;http://support.microsoft.com/kb/257819&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c1131&quot;&gt;http://www.codeguru.com/cpp/data/mfc_database/microsoftexcel/article.php/c1131&lt;/a&gt;&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/7660862066851368281/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/library-to-write-excel-file.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/7660862066851368281'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/7660862066851368281'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/library-to-write-excel-file.html' title='Library To Write An Excel File'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-1864572098456719180</id><published>2023-10-05T23:54:00.001-07:00</published><updated>2023-10-05T23:54:14.822-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Vba - Loop Through Files In A Folder Only If Multiple Conditions Are Met</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I am currently using a piece of code to loop through files in a folder and copy certain cells from each file into a master list. There are a number of files being added into the fo&lt;/div&gt;
&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;
&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I ran into a similar problem when copying a range into an array. What fixed it was using .Value2 instead of .Value. Might be worth a try. &lt;/p&gt;&lt;/div&gt; 
&lt;br&gt;
</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/1864572098456719180/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/vba-loop-through-files-in-folder-only.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1864572098456719180'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/1864572098456719180'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/vba-loop-through-files-in-folder-only.html' title='Vba - Loop Through Files In A Folder Only If Multiple Conditions Are Met'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-3068393981238911621</id><published>2023-10-05T23:29:00.001-07:00</published><updated>2023-10-05T23:29:24.777-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>How To Tell If Text Fits In A Cell?</title><content type='html'>&lt;div class=&quot;question&quot;&gt;I would like to write some vba code that monitors the OnChange event for a sheet and does some adjustment if text does not fit a cell.  I.e. make the text smaller or wrap etc.. I k&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;Quick and dirty way which will not require you to check each and every cell.&lt;/p&gt;&lt;p&gt;I use this method to usually show all the data.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Sample()
    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Thisworbook.Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Sheet1&quot;&lt;/span&gt;).Cells
        .ColumnWidth = &lt;span class=&quot;hljs-number&quot;&gt;254.86&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;&amp;lt;~~ Max Width&lt;/span&gt;
        .RowHeight = &lt;span class=&quot;hljs-number&quot;&gt;409.5&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;&amp;lt;~~ Max Height&lt;/span&gt;
        .EntireRow.AutoFit
        .EntireColumn.AutoFit
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;I use this method if I want to wrap the text (If Applicable) and keep the row width constant&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Sample()
    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; Thisworbook.Sheets(&lt;span class=&quot;hljs-string&quot;&gt;&quot;Sheet1&quot;&lt;/span&gt;).Cells
        .ColumnWidth = &lt;span class=&quot;hljs-number&quot;&gt;41.71&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;&amp;lt;~~ Keep the column width constant&lt;/span&gt;
        .RowHeight = &lt;span class=&quot;hljs-number&quot;&gt;409.5&lt;/span&gt;
        .EntireRow.AutoFit
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: This is not applicable for merged cells. For that there is a separate method.&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;I&#39;m using THE &quot;dirty&quot; method - that&#39;s only one I know: force &lt;code&gt;AutoFit&lt;/code&gt; and check new width/height.&lt;/p&gt;&lt;p&gt;However, we can&#39;t grantee that was chosen cell that forced new fit. So I opt by copying cell content to an empty worksheet.&lt;/p&gt;&lt;p&gt;That, of course, cause a lot of other problems, and more workarounds.&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Private&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Worksheet_Change(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; Target &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range)
    &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Not&lt;/span&gt; Fits(Target) &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Notice that Target may have multiple cells!!!&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; Fits(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; Range &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range) &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Boolean&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; cell &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range, tmp_cell &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt; Range, da &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Boolean&lt;/span&gt;, su &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Boolean&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Stores current state and disables ScreenUpdating and DisplayAlerts&lt;/span&gt;
    su = Application.ScreenUpdating: Application.ScreenUpdating = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
    da = Application.DisplayAlerts: Application.DisplayAlerts = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Creates a new worksheet and uses first cell as temporary cell&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; tmp_cell = Range.Worksheet.Parent.Worksheets.Add.Cells(&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;, &lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;)
    &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Assume fits by default&lt;/span&gt;
    Fits = &lt;span class=&quot;hljs-literal&quot;&gt;True&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Enumerate all cells in Range&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; cell &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; Range.Cells
        &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Copy cell to temporary cell&lt;/span&gt;
        cell.Copy tmp_cell
        &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Copy cell value to temporary cell, if formula was used&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; cell.HasFormula &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt; tmp_cell.Value = cell.Value
        &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Checking depends on WrapText&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; cell.WrapText &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Ensure temporary cell column is equal to original&lt;/span&gt;
            tmp_cell.ColumnWidth = cell.ColumnWidth
            tmp_cell.EntireRow.AutoFit &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Force fitting&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; tmp_cell.RowHeight &amp;gt; cell.RowHeight &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Cell doesn&#39;t fit!&lt;/span&gt;
                Fits = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Exit For loop (at least one cell doesn&#39;t fit)&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
            tmp_cell.EntireColumn.AutoFit &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Force fitting&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; tmp_cell.ColumnWidth &amp;gt; cell.ColumnWidth &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Cell doesn&#39;t fit!&lt;/span&gt;
                Fits = &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Exit For loop (at least one cell doesn&#39;t fit)&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt;
    tmp_cell.Worksheet.Delete &lt;span class=&quot;hljs-comment&quot;&gt;&#39;Delete temporary Worksheet&lt;/span&gt;&lt;span class=&quot;hljs-comment&quot;&gt;&#39;Restore ScreenUpdating and DisplayAlerts state&lt;/span&gt;
    Application.DisplayAlerts = da
    Application.ScreenUpdating = su
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Has solution got too complex, there may be some problems I didn&#39;t preview.&lt;/p&gt;&lt;p&gt;This won&#39;t work in read-only workbooks, however, cells in read-only workbooks don&#39;t change as well!&lt;/p&gt;&lt;/div&gt; 


</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/3068393981238911621/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-tell-if-text-fits-in-cell.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3068393981238911621'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/3068393981238911621'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/how-to-tell-if-text-fits-in-cell.html' title='How To Tell If Text Fits In A Cell?'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-5520865691253935674.post-5848964400104694074</id><published>2023-10-05T21:08:00.001-07:00</published><updated>2023-10-05T21:08:24.623-07:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel 2010"/><category scheme="http://www.blogger.com/atom/ns#" term="Vba"/><title type='text'>Find The Current User Language</title><content type='html'>&lt;div class=&quot;question&quot;&gt;How can I tell the current user language in a vba program?  I need this to show a form in an appropriate language.&lt;/div&gt;&lt;h2 id=&quot;solution_1&quot;&gt;Solution 1:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;My initial code (utilising this &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;http://www.vbforums.com/showthread.php?t=610740&quot;&gt;vbforum code&lt;/a&gt;) assumed that Windows and Excel share a common language - likely but not bulletproof.&lt;/p&gt;&lt;p&gt;&lt;em&gt;updated&lt;/em&gt;&lt;/p&gt;&lt;p&gt;The revised code:&lt;/p&gt;&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;ol&gt;&lt;li&gt;Returns the Locale ID (LCID).&lt;/li&gt;&lt;li&gt;Looks up the LCID from this &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://msdn.microsoft.com/en-us/goglobal/bb964664&quot;&gt;msft link&lt;/a&gt;.&lt;/li&gt;&lt;li&gt;Parses the LCID using a &lt;a rel=&quot;nofollow noreferrer noopener&quot; class=&quot;post-tag&quot; href=&quot;/questions/tagged/regexp&quot; title=&quot;show questions tagged &#39;regexp&#39;&quot;&gt;regexp&lt;/a&gt; to get the language.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;strong&gt;Sample output on my machine below&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;The code will let the user know if there are any errors in accessing the LCID website, or in parsing the country name.&lt;/p&gt;&lt;p&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/BtRYm.png&quot;&gt;&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_0&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; GetXlLang()
        &lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; lngCode &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;
        lngCode = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
        MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;Code is: &quot;&lt;/span&gt; &amp;amp; lngCode &amp;amp; vbNewLine &amp;amp; GetTxt(lngCode)
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; GetTxt(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; lngCode) &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; objXmlHTTP &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; objRegex &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; objRegMC &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; strResponse &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; strSite &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objXmlHTTP = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;MSXML2.XMLHTTP&quot;&lt;/span&gt;)
        strSite = &lt;span class=&quot;hljs-string&quot;&gt;&quot;http://msdn.microsoft.com/en-us/goglobal/bb964664&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt; ErrHandler
        &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; objXmlHTTP
            .Open &lt;span class=&quot;hljs-string&quot;&gt;&quot;GET&quot;&lt;/span&gt;, strSite, &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
            .Send
            &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; .Status = &lt;span class=&quot;hljs-number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt; strResponse = .ResponseText
        &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;

        strResponse = Replace(strResponse, &lt;span class=&quot;hljs-string&quot;&gt;&quot;&amp;lt;/td&amp;gt;&amp;lt;td&amp;gt;&quot;&lt;/span&gt;, vbNullString)
        &lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objRegex = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;vbscript.regexp&quot;&lt;/span&gt;)
        &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; objRegex
            .Pattern = &lt;span class=&quot;hljs-string&quot;&gt;&quot;&amp;gt;&amp;lt;td&amp;gt;([a-zA-Z- ]+)[A-Fa-f0-9]{4}&quot;&lt;/span&gt; &amp;amp; lngCode                    
            &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; .Test(strResponse) &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objRegMC = .Execute(strResponse)
                GetTxt = objRegMC(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;).submatches(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)
            &lt;span class=&quot;hljs-keyword&quot;&gt;Else&lt;/span&gt;
                GetTxt = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Value not found from &quot;&lt;/span&gt; &amp;amp; strSite
            &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objRegex = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objXmlHTTP = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;hljs-symbol&quot;&gt;ErrHandler:&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Not&lt;/span&gt; objXmlHTTP &lt;span class=&quot;hljs-built_in&quot;&gt;Is&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; objXmlHTTP = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;
        GetTxt = strSite &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; unable to be accessed&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_0&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_2&quot;&gt;Solution 2:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_1&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;dim&lt;/span&gt; lang_code &lt;span class=&quot;hljs-keyword&quot;&gt;as&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;long&lt;/span&gt;
lang_code = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_1&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_3&quot;&gt;Solution 3:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;This is another variation of the code posted by brettdj&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_2&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt; Test_GetLocale_UDF()
&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; lngCode &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;

lngCode = Application.LanguageSettings.LanguageID(msoLanguageIDUI)
MsgBox &lt;span class=&quot;hljs-string&quot;&gt;&quot;Code Is: &quot;&lt;/span&gt; &amp;amp; lngCode &amp;amp; vbNewLine &amp;amp; GetLocale(lngCode)
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Sub&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; GetLocale(&lt;span class=&quot;hljs-keyword&quot;&gt;ByVal&lt;/span&gt; lngCode) &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; html            &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; http            &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; htmlTable       &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; htmlRow         &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; htmlCell        &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Dim&lt;/span&gt; url             &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; html = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;htmlfile&quot;&lt;/span&gt;)
&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; http = CreateObject(&lt;span class=&quot;hljs-string&quot;&gt;&quot;MSXML2.XMLHTTP&quot;&lt;/span&gt;)
url = &lt;span class=&quot;hljs-string&quot;&gt;&quot;https://www.science.co.il/language/Locale-codes.php&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt; ErrHandler
    &lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt; http
        .Open &lt;span class=&quot;hljs-string&quot;&gt;&quot;GET&quot;&lt;/span&gt;, url, &lt;span class=&quot;hljs-literal&quot;&gt;False&lt;/span&gt;
        .send
        &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; .Status = &lt;span class=&quot;hljs-number&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt; html.body.innerHTML = .responseText
    &lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;With&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;On&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;GoTo&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; htmlTable = html.getElementsByTagName(&lt;span class=&quot;hljs-string&quot;&gt;&quot;table&quot;&lt;/span&gt;)(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;)

&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; htmlRow &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; htmlTable.getElementsByTagName(&lt;span class=&quot;hljs-string&quot;&gt;&quot;tr&quot;&lt;/span&gt;)
    &lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Each&lt;/span&gt; htmlCell &lt;span class=&quot;hljs-keyword&quot;&gt;In&lt;/span&gt; htmlRow.Children
        &lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; htmlCell.innerText = &lt;span class=&quot;hljs-built_in&quot;&gt;CStr&lt;/span&gt;(lngCode) &lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;
            GetLocale = htmlRow.getElementsByTagName(&lt;span class=&quot;hljs-string&quot;&gt;&quot;td&quot;&lt;/span&gt;)(&lt;span class=&quot;hljs-number&quot;&gt;0&lt;/span&gt;).innerText
            &lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;For&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; htmlCell
&lt;span class=&quot;hljs-keyword&quot;&gt;Next&lt;/span&gt; htmlRow

&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt; GetLocale = &lt;span class=&quot;hljs-string&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt; GetLocale = &lt;span class=&quot;hljs-string&quot;&gt;&quot;Value Not Found From &quot;&lt;/span&gt; &amp;amp; url

&lt;span class=&quot;hljs-keyword&quot;&gt;Exit&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;span class=&quot;hljs-symbol&quot;&gt;ErrHandler:&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;If&lt;/span&gt;&lt;span class=&quot;hljs-built_in&quot;&gt;Not&lt;/span&gt; http &lt;span class=&quot;hljs-built_in&quot;&gt;Is&lt;/span&gt;&lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Then&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Set&lt;/span&gt; http = &lt;span class=&quot;hljs-literal&quot;&gt;Nothing&lt;/span&gt;
GetLocale = url &amp;amp; &lt;span class=&quot;hljs-string&quot;&gt;&quot; Unable To Be Accessed&quot;&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_2&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_4&quot;&gt;Solution 4:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;pre&gt;&lt;code id=&quot;code_3&quot; class=&quot;hljs language-sql&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Case&lt;/span&gt; Application.International(xlApplicationInternational.xlCountryCode) 
   &lt;span class=&quot;hljs-keyword&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;1&lt;/span&gt;: &lt;span class=&quot;hljs-keyword&quot;&gt;Call&lt;/span&gt; MsgBox(&quot;English&quot;) 
   &lt;span class=&quot;hljs-keyword&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;33&lt;/span&gt;: &lt;span class=&quot;hljs-keyword&quot;&gt;Call&lt;/span&gt; MsgBox(&quot;French&quot;) 
   &lt;span class=&quot;hljs-keyword&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;49&lt;/span&gt;: &lt;span class=&quot;hljs-keyword&quot;&gt;Call&lt;/span&gt; MsgBox(&quot;German&quot;) 
   &lt;span class=&quot;hljs-keyword&quot;&gt;Case&lt;/span&gt;&lt;span class=&quot;hljs-number&quot;&gt;81&lt;/span&gt;: &lt;span class=&quot;hljs-keyword&quot;&gt;Call&lt;/span&gt; MsgBox(&quot;Japanese&quot;) 
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Select&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_3&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Straight out of here: &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://bettersolutions.com/vba/macros/region-language.htm&quot;&gt;https://bettersolutions.com/vba/macros/region-language.htm&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Relevant Documentation: &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/office/vba/api/excel.xlapplicationinternational&quot;&gt;https://docs.microsoft.com/en-us/office/vba/api/excel.xlapplicationinternational&lt;/a&gt;&lt;/p&gt;&lt;/div&gt;&lt;h2 id=&quot;solution_5&quot;&gt;Solution 5:

&lt;/h2&gt;&lt;div class=&quot;answer-desc&quot;&gt;&lt;p&gt;VBA &lt;code&gt;Application.LanguageSettings.LanguageID(msoLanguageIDUI)&lt;/code&gt; gets only Microsoft Office Access or Microsoft Excel User interface Language. But does not reflect the Windows System display language used for Windows Display, every thing as &lt;code&gt;MsgBox()&lt;/code&gt; buttons etc.&lt;/p&gt;&lt;p&gt;If user changes his Windows Display language via Windows Control Panel, this Application level setting will not change. In which case, we can use this Kernel dll function to get the new &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f&quot;&gt;LCID&lt;/a&gt; (Microsoft Language Code IDentifier, 1036=French, 1033=English, ...), with this code in a VBA Module:&lt;/p&gt;&lt;pre&gt;&lt;code id=&quot;code_6&quot; class=&quot;hljs language-vbnet&quot;&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Private&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Declare&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; GetUserDefaultUILanguage &lt;span class=&quot;hljs-keyword&quot;&gt;Lib&lt;/span&gt;&lt;span class=&quot;hljs-string&quot;&gt;&quot;kernel32.dll&quot;&lt;/span&gt; () &lt;span class=&quot;hljs-keyword&quot;&gt;As&lt;/span&gt;&lt;span class=&quot;hljs-type&quot;&gt;Long&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Public&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt; winGetUserDefaultUILanguage()
  winGetUserDefaultUILanguage = GetUserDefaultUILanguage()
&lt;span class=&quot;hljs-keyword&quot;&gt;End&lt;/span&gt;&lt;span class=&quot;hljs-keyword&quot;&gt;Function&lt;/span&gt;&lt;/code&gt;&lt;button class=&quot;copy-btn btn btn-secondary btn-sm&quot; onclick=&quot;copyCode(this,&#39;code_6&#39;)&quot;&gt;Copy&lt;/button&gt;&lt;/pre&gt;&lt;p&gt;Then you can call the public function &lt;code&gt;winGetUserDefaultUILanguage()&lt;/code&gt; every where in your VBA code to get Windows LCID.&lt;/p&gt;&lt;p&gt;The kernel dll function &lt;code&gt;GetUserDefaultUILanguage()&lt;/code&gt; will reflect the changement via Windows Display Language ID.&lt;/p&gt;&lt;hr&gt;&lt;p&gt;For example, as I&#39;ve French Windows display language, LCID=1036, my Office is also in French (LCID=1036),&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/HGhT5.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/HGhT5.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;VBA Debugger Console:&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/kt1fW.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/kt1fW.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;hr&gt;&lt;p&gt;Now we switch to English Windows display language via Control Panel (LCID=1033 for English), but my Office language ID remains unchanged (LCID=1036):&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/dWMWa.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/dWMWa.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;VBA Debugger Console:&lt;/p&gt;&lt;p&gt;&lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://i.stack.imgur.com/W3GLN.png&quot;&gt;&lt;img alt=&quot;enter image description here&quot; src=&quot;https://i.stack.imgur.com/W3GLN.png&quot;&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;From LCID, you can further get Language Tag, Language Name from &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/70feba9f-294e-491e-b6eb-56532684c37f&quot;&gt;Microsoft API documents here&lt;/a&gt; or &lt;a rel=&quot;nofollow noreferrer noopener&quot; href=&quot;https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-lcid/a9eac961-e77d-41a6-90a5-ce1a8b0cdb9c?redirectedfrom=MSDN&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;&lt;/div&gt; 

</content><link rel='replies' type='application/atom+xml' href='https://norfaezahsuhaimi.blogspot.com/feeds/5848964400104694074/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/find-current-user-language.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/5848964400104694074'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/5520865691253935674/posts/default/5848964400104694074'/><link rel='alternate' type='text/html' href='https://norfaezahsuhaimi.blogspot.com/2023/10/find-current-user-language.html' title='Find The Current User Language'/><author><name>Miss Ben Koch</name><uri>http://www.blogger.com/profile/05261056798222768412</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>