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

<channel>
	<title>Open Script Solution&#187; export</title>
	<atom:link href="http://www.openscriptsolution.com/tag/export/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.openscriptsolution.com</link>
	<description>... where solutions for script programming are found ...</description>
	<lastBuildDate>Tue, 31 Jan 2012 03:22:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to Convert 5 Digits Numeral to The Date Value?</title>
		<link>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/</link>
		<comments>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 02:48:01 +0000</pubDate>
		<dc:creator>Masino Sinaga</dc:creator>
				<category><![CDATA[Date and Time]]></category>
		<category><![CDATA[Access]]></category>
		<category><![CDATA[convert]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[digits]]></category>
		<category><![CDATA[Excel]]></category>
		<category><![CDATA[export]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[Macro]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://www.openscriptsolution.com/?p=125</guid>
		<description><![CDATA[A few days ago, a friend of mine asked me for help. He wanted to export his data from Excel file into Access database file. There were about sixteen thousand rows in Excel that have to be exported into Access. One of the columns in that Excel had a Date data. Unfortunately, most of those [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago, a friend of mine asked me for help. He wanted to export his data from Excel file into Access database file. There were about sixteen thousand rows in Excel that have to be exported into Access. One of the columns in that Excel had a Date data. Unfortunately, most of those rows have the 5 digits numeral data, and not in the real Date Value data. For example, there was a row with value <strong>&#8217;38353</strong>. As we know, this is not a valid Date, right? Besides that, there is a &#8216; character before the value itself. In this case, that value become a String and not a numeral value anymore. <span id="more-125"></span></p>
<p>If the data does not contain of the &#8216; character at beginning, it is so easy to convert them become Date value, by using Format Cells feature in Excel. Obviously, it took too long time if I have to remove first the &#8216; character for those thousand records, and then do formatting the cell column. Since the date have the &#8216; character, then it will take a long time to remove that character one by one. Even if you want to make the special function to remove this.</p>
<p>So, before I export all about those sixteen thousand rows, I analyzed, which one the best way to do this. Well, finally, I think it is better to convert first those 5 digits numeral data directly to the real Date Value data without having to remove the &#8216; character. I also have to convert this data become the Date format and order: <strong>year-month-date</strong>, such as &#8220;yyyy-MM-dd&#8221;. This &#8220;38353&#8243; value should be like <strong>2005-01-01</strong>. </p>
<p>Actually, the solution that I made for this, is only by using <strong>CDate()</strong> function belongs to VBA (Visual Basic Application) that exists in Excel file. Unfortunately, you cannot use formula <strong>=CDATE()</strong> function directly in the Excel WorkSheet Cell. So, I created this function below from Visual Basic Editor in the Excel file and run it from Macro Excel:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
</pre></td><td class="code"><pre class="vb" style="font-family:monospace;"><span style="color: #E56717; font-weight: bold;">Public</span> <span style="color: #E56717; font-weight: bold;">Function</span> ConvertDateStringToDateValue()
  <span style="color: #8D38C9; font-weight: bold;">With</span> Sheet1
    <span style="color: #8D38C9; font-weight: bold;">For</span> i = 2 <span style="color: #8D38C9; font-weight: bold;">To</span> 16000 <span style="color: #008000;">'first row is the header column, so we start from the 2nd row
</span>      <span style="color: #8D38C9; font-weight: bold;">If</span> IsDate(.Cells(i, 7)) <span style="color: #8D38C9; font-weight: bold;">Then</span> <span style="color: #008000;">'check whether the Date value in the 7th column
</span>        <span style="color: #008000;">'among those 16,000 rows, not all rows contain of the DateString
</span>        <span style="color: #008000;">'so, if the Cell value is a real Date, do nothing here...
</span>      <span style="color: #8D38C9; font-weight: bold;">Else</span> <span style="color: #008000;">'Else, if the cell value not a Date type
</span>        <span style="color: #008000;">'let's convert the Cell here, and put the result in to the 11th column
</span>        .Cells(i, 11).Value = Format(CDate(.Cells(i, 7).Value), <span style="color: #800000;">&quot;yyyy-MM-dd&quot;</span>)
      <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">If</span>
    <span style="color: #8D38C9; font-weight: bold;">Next</span> i
  <span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #8D38C9; font-weight: bold;">With</span>
<span style="color: #8D38C9; font-weight: bold;">End</span> <span style="color: #E56717; font-weight: bold;">Function</span></pre></td></tr></table></div>

<p>From the code above, we can see that the 5 digits numeral value located on the seventh column or column <strong>G</strong>, meanwhile the real Date Value I put on the eleventh column or column <strong>K</strong> in Excel file.</p>
<p>The conclusion? Well, the solution I made is by using <strong>CDate()</strong> and <strong>Format()</strong> function in Visual Basic Application (VBA) from Visual Basic editor belongs to the Excel file. We cannot use the Excel formula directly on the Sheet.  It took only moreless about a few seconds to convert the 5 digits numeral to the Date Value. Meanwhile, the export process itself from the Excel file into the Access database file took only a few seconds, too.  I just used the <strong>Get External Data</strong> from the Access database file from menu: &#8220;File -&gt; Get External Data -&gt; Import&#8230;&#8221;.</p>
<p>Thanks to the <strong>CDate()</strong> and <strong>Format()</strong> functions that available in VBA Excel, and also to the <strong>Get External Data</strong> feature that available in Microsoft Access.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.openscriptsolution.com%2F2009%2F08%2F28%2Fhow-to-convert-5-digits-numeral-to-the-date-value%2F&amp;title=How%20to%20Convert%205%20Digits%20Numeral%20to%20The%20Date%20Value%3F" id="wpa2a_2"><img src="http://www.openscriptsolution.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.openscriptsolution.com/2009/08/28/how-to-convert-5-digits-numeral-to-the-date-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
