473,395 Members | 1,527 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Excel 2000 Date issue when transferring to new workbook

63
I have a problem in Excel 2000. I have written some VBA code that transfers data from the current excel workbook to a file called "Deal Input2.xls". Everything transfers ok apart from the date in cell ("G28"). This gets converted into an American date in Deal input 2.xls. So even though the date in the current workbook is entered as 02/05/2008 the info gets transferred to deal input2.xls as 05/02/2008. I've played around by trying to change the format of the cell in both files to text, different date formats etc - but it doesn't seem to make much difference. I've heard that a command called local:=true might be able to help me - but I have no idea where to add this! The current code is as follows: Any help would be greatly appreciated



Sub Import()

Dim stdocname As String
Dim DealNo As Range
Dim DealDate As Range
Dim ValDate As Range
Dim Cparty As Range
Dim Ext_Name As Range
Dim Cucy1 As Range
Dim Cucy2 As Range
Dim Value1 As Range
Dim Value2 As Range
Dim XRate As Range
Dim spot As Range
Dim Draw As Range
Dim ESett As Range
Dim Canx As Range
Dim SettCode As Range
' Dim SendTo As String
' Dim objOL As New Outlook.Application
' Dim objMail As MailItem
' Dim MyMessage As Range


Application.ScreenUpdating = False

Set DealNo = Worksheets("Internal FX Contract").Range("G32")
Set DealDate = Worksheets("Internal FX Contract").Range("G9")
Set ValDate = Worksheets("Internal FX Contract").Range("G28")
Set Cparty = Worksheets("Internal FX Contract").Range("G17")
Set Ext_Name = Worksheets("Internal FX Contract").Range("B17")
Set Cucy1 = Worksheets("Internal FX Contract").Range("E31")
Set Cucy2 = Worksheets("Internal FX Contract").Range("E35")
Set Value1 = Worksheets("Internal FX Contract").Range("F31")
Set Value2 = Worksheets("Internal FX Contract").Range("F35")
Set XRate = Worksheets("Internal FX Contract").Range("F33")
Set spot = Worksheets("Internal FX Contract").Range("B22")
Set Draw = Worksheets("Internal FX Contract").Range("B24")
Set ESett = Worksheets("Internal FX Contract").Range("B26")
Set Canx = Worksheets("Internal FX Contract").Range("B28")
Set SettCode = Worksheets("Internal FX Contract").Range("F42")

If spot.Value = "True" Then

stdocname = "Q:\Reuters Analytical Models\Quantum\Input\Deal Input2.xls"
Workbooks.Open Filename:=stdocname, UpdateLinks:=False

Workbooks("Deal Input2.xls").Activate
Sheets("Data").Activate
If Range("B2") = "" Then
Range("A2").Value = "Dummy"
Else
End If
Rows("2:2").Select
Selection.Insert Shift:=xlDown
Range("A2").Value = DealNo.Value
Range("B2").Value = Cparty.Value
Range("C2").Value = Ext_Name.Value
Range("D2").Value = DealDate.Value
Range("E2").Value = ValDate.Value
Range("F2").Value = "Foreign Exchange Spot"
Range("H2").Value = Cucy1.Value
Range("I2").Value = Value1.Value
Range("J2").Value = Cucy2.Value
Range("K2").Value = Value2.Value
Range("L2").Value = XRate.Value
Range("O2").Value = SettCode.Value

If Range("A3").Value = "Dummy" Then
Range("A3").Value = ""
Else
End If

ActiveWorkbook.Close SaveChanges:=True

Else
End If
ActiveWindow.SelectedSheets.Printout Copies:=1, Collate:=True

' Send confirmation e-mail

' SendTo = Range("F11").Value
' subj = "Successfully processed - Foreign Exchange Contract"
' Set objOL = New Outlook.Application
' Set objMail = objOL.CreateItem(olMailItem)
' Set MyMessage = Range("A60")

' With objMail
' .To = SendTo
' .CC = sendcc
' .Subject = subj
' .Body = MyMessage.Value
' .Display
' End With

' objMail.Send
' Set objMail = Nothing
' Set objOL = Nothing
' Set MyMessage = Nothing


Application.ScreenUpdating = True

End Sub
May 2 '08 #1
2 1686
kadghar
1,295 Expert 1GB
I have a problem in Excel 2000. I have written some VBA code that transfers data from the current excel workbook to a file called "Deal Input2.xls". Everything transfers ok apart from the date in cell ("G28"). This gets converted into an American date in Deal input 2.xls. So even though the date in the current workbook is entered as 02/05/2008 the info gets transferred to deal input2.xls as 05/02/2008. I've played around by trying to change the format of the cell in both files to text, different date formats etc - but it doesn't seem to make much difference. I've heard that a command called local:=true might be able to help me - but I have no idea where to add this! The current code is as follows: Any help would be greatly appreciated
Why dont you use a Date variable instead of a Range one, this might help a little bit, i.e:

instead of

Expand|Select|Wrap|Line Numbers
  1. Dim Canx As Range
define it as

Expand|Select|Wrap|Line Numbers
  1. Dim Canx As Date
This way, the date will be stored as a numeric value, and you'll forget about its format.

And then, when it's already in the new workbook, just change the cell's format:

Expand|Select|Wrap|Line Numbers
  1. Range("G28").NumberFormat = "m/d;@"
And always try to manage dates with numeric values, only formating them when showing them.

HTH.
May 2 '08 #2
grego9
63
Worked a treat - I had a few other issues with the set command - but I just removed Set and the .value bits against the relevant date and it worked fine.

Thanks for your help
May 7 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Geert-Pieter Hof | last post by:
Hello, My VB 6.0 application read and writes data from and to a MS Excel workbook, using the Microsoft.Jet.OLEDB.4.0 provider. Now I want to protect the Excel workbook with a password, but I...
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
8
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a...
6
by: Matthew Wieder | last post by:
I have the following requirements: Build a stand-alone C# application that asks the user to click in a cell in an Excel spreadsheet, and then displays the address of that cell in the C#...
1
by: kumar yogesh via .NET 247 | last post by:
Hello, I want to develop an application to transfer data from sqlserver to excel such that , when we create a workbook in excel ,then we are able to transfer data from SQL Server to excel in away...
8
by: Sam | last post by:
Hi All, I posted this message few days ago. No one has answered so far. I just would like to know if it is possible to do or not. Even if you can not tell me how to do this, maybe you know which...
0
by: Larry Jones | last post by:
I am pulling Excel single cell information from a workbook to a textbox in a VB.net form. Most of the information is transferring without a problem, but some cells with function calculations are...
7
by: Alain \Mbuna\ | last post by:
Hi everybody. In my program I have some data that is calculated after some input from the user. I have written some code that opens an Excel workbook, with 5 worksheets and the calculated data...
2
by: Jim S | last post by:
To my surprise and chagrin, newer versions of Access have disabled the functionality that lets users change the data in linked tables that point to a range in an Excel workbook. This is "because of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.