Formatting from CopyFromRecordset

jasontf

New Member
Joined
Mar 9, 2011
Messages
1
I have a strange problem. I am using CopyFromRecordset to paste some data from a database, then formatting the data. The first column includes a date, so it comes in as a Julian value, then I format it to mm/dd/yyyy. This is on Sheet1. Then, I use CopyFromRecordset for another select statement and put it in Sheet2. It also has a date in the first column. At this point, the first column of Sheet1, only where the range overlaps with Sheet2, changes format to m/d/yyyy. The header row and unpopulated rows still have the mm/dd/yyyy format.

Searching forums, I found this problem that sounds similar. Any ideas as to why using CopyFromRecordset on one sheet would affect a different sheet in the same workbook?
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_24760549.html

A snippet of the code looks like this: (a different sheet is activated during the process)
Set rsResult = cmDB.Execute
shtHours.Range("A2").CopyFromRecordset rsResult
shtHours.Range("A:A").NumberFormat = "mm/dd/yyyy"
shtHours.UsedRange.Columns.AutoFit
sql=yadayada
cmDB.CommandText = sql
Set rsResult = cmDB.Execute
shtGas.Range("A2").CopyFromRecordset rsResult
shtGas.Range("A:A").NumberFormat = "mm/dd/yyyy"

shtHours is the sheet that gets the "m/d/yyyy" format in column A.
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Forum statistics

Threads
1,223,886
Messages
6,175,193
Members
452,616
Latest member
intern444

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top