I went to Tool -- Microsoft Script Editor and I got below form the Macro
(called 'Macro1') and I saved it in the Personal Macro Workook, which is a
folder called 'Personal'. Thank you so much!
<html xmlns
="urn:schemas-microsoft-com
ffice
ffice"
xmlns:x="urn:schemas-microsoft-com
ffice:excel"
xmlns="
http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<meta name=ProgId content=Excel.Sheet>
<meta name=Generator content="Microsoft Excel 11">
<link rel=File-List href="PERSONAL_files/filelist.xml">
<link rel=Edit-Time-Data href="PERSONAL_files/editdata.mso">
<link rel=OLE-Object-Data href="PERSONAL_files/oledata.mso">
<!--[if gte mso 9]><xml>
<o
ocumentProperties>
<o:Author>0710058c</o:Author>
<o:LastAuthor>0710058c</o:LastAuthor>
<o:Created>2009-06-06T14:50:25Z</o:Created>
<o:LastSaved>2009-06-06T14:53:26Z</o:LastSaved>
<o:Company>UoG</o:Company>
<o:Version>11.9999</o:Version>
</o
ocumentProperties>
</xml><![endif]-->
<style>
<!--table
{mso-displayed-decimal-separator:"\.";
mso-displayed-thousand-separator:"\,";}
@page
{margin:1.0in .75in 1.0in .75in;
mso-header-margin:.5in;
mso-footer-margin:.5in;}
tr
{mso-height-source:auto;}
col
{mso-width-source:auto;}
br
{mso-data-placement:same-cell;}
.style0
{mso-number-format:General;
text-align:general;
vertical-align:bottom;
white-space:nowrap;
mso-rotate:0;
mso-background-source:auto;
mso-pattern:auto;
color:windowtext;
font-size:10.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Arial;
mso-generic-font-family:auto;
mso-font-charset:134;
border:none;
mso-protection:locked visible;
mso-style-name:Normal;
mso-style-id:0;}
td
{mso-style-parent:style0;
padding-top:1px;
padding-right:1px;
padding-left:1px;
mso-ignore
adding;
color:windowtext;
font-size:10.0pt;
font-weight:400;
font-style:normal;
text-decoration:none;
font-family:Arial;
mso-generic-font-family:auto;
mso-font-charset:134;
mso-number-format:General;
text-align:general;
vertical-align:bottom;
border:none;
mso-background-source:auto;
mso-pattern:auto;
mso-protection:locked visible;
white-space:nowrap;
mso-rotate:0;}
-->
</style>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>Sheet1</x:Name>
<x:WorksheetOptions>
<x:CodeName></x:CodeName>
<x:Selected/>
<x
rotectContents>False</x
rotectContents>
<x
rotectObjects>False</x
rotectObjects>
<x
rotectScenarios>False</x
rotectScenarios>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
<x:WindowHidden/>
<x:WindowHeight>8445</x:WindowHeight>
<x:WindowWidth>13275</x:WindowWidth>
<x:WindowTopX>480</x:WindowTopX>
<x:WindowTopY>60</x:WindowTopY>
<x
rotectStructure>False</x
rotectStructure>
<x
rotectWindows>False</x
rotectWindows>
</x:ExcelWorkbook>
</xml><![endif]-->
</head>
<body link=blue vlink=purple>
<table x:str border=0 cellpadding=0 cellspacing=0 width=64
style='border-collapse:
collapse;table-layout:fixed;width:48pt'>
<col width=64 style='width:48pt'>
<tr height=17 style='height:12.75pt'>
<td height=17 width=64 style='height:12.75pt;width:48pt'></td>
</tr>
<![if supportMisalignedColumns]>
<tr height=0 style='display:none'>
<td width=64 style='width:48pt'></td>
</tr>
<![endif]>
</table>
</body>
</html>
--
Tatiana
:
Post the query you got from the recorded macro. You can filter the SQL to
get the dates within a range of dates. Perform a nd query while recording a
macro and when you get to the 2nd menu (filter) set the 1s filter to after
and put in the start date and then select a 2nd obx and use the filter before
for the 2nd date. Then post the query results. You can use a connection to
get all the obecjt between th e 2 dates.
:
Thank you so much for the advice. There is a small problem regarding changing
the format of dates in Column A though. I only can search the date 31 Jan 88
but I cannot change it within MS query. Yes, in my last post, I thought I
can change the dates. "It is feasible to open the database and retrieve the
data one row at a timeâ€. Do you know how? Thanks!
--
Tatiana
:
See below
:
Hi Joel,
I’m sorry for the confusion I caused. My data is in an Excel file called
Excelhanding.xls. The format of it were distorted after copying and pasting.
It should be:
Column A Column B Column C Column D Column E Column F
Time Debt Company Issuing date Year Arranged Debt
31 Jan 88 2.3343 A0004 30/12/2001 1988 3.0045
28 Feb 88 3.5674 A0004 30/04/2002 1989 3.0482
31 Mar 88 4.5711 A0004 30/09/2003 1990
… … A0004 01/04/2004 …
31 Dec 88 3.0045 A0004 30/09/2005 …
… … A0005 31/12/1989 …
31 Dec 89 3.0482 A0005 31/12/1990 …
31 Dec 01 3.1124 … … …
… … … … …
31 Dec 05 4.5711 … … 2001 3.1124
… … …
... … … 2005
… … … 1988
… … … …
A0005 31/12/2005 2001 … 2005
…
You’re absolutely right.! For Column A, I only have monthly data from Jan
31, 1988 to Dec 31, 2005. It is feasible to “open the database and retrieve
the data one row at a timeâ€. I just think it will be a good exercise to learn
SQL. After all, I always in a situation where I need to change Jan 31 88 to
31/12/1988 and to compare two columns.
1) I’d like to “format the data which already exists in the Excel
worksheetâ€. That said, I need to fill the Column F with the content of Column
B within this Excelhandling.xls. I’m reading two books on SQL Server 2005
Programming, a book on Excel and a book called “Integrating Excel and
Accessâ€, which also talked some basic Microsoft Visual Basic (VBA). However,
after all this reading, I’m still confused about whether I should use
Microsoft SQL Server 2000, which requires a server, VBA or Microsoft Query
(to write a program using the SQL window). I don’t think I can use Macros
though.
-------------------------------------------------------------------------------------------
You don't need a server for SQL. the SQL is really the CommandText portion
of the query. Dont learn SQL let Excel generate it for you. Start recording
a macro from the worksheet menu - tools - Macro _record New Macro. Then
perform a query by going to worksheet menu Data - Import External Data.
Choose any of the query methods.
-------------------------------------------------------------------------------------------
2) The purpose of changing the format of Column A, is to be able to compare
with Column D. Since, for example, Column A is 31 Dec 2001, I guess I have to
change it to 31/12/2001 to be recognized. This 31/12/2001 stands for the
period of 01/12/2001 to 31/12/2001. 30/12/2001 in Column D falls into this
period. Therefore 3.1124 in Column B is put the place in Column F. That is
also the reason the date does not matter. As long as Dec 01 in Column A is
correspond to 12/2001 in Column D, we can put this 3.1124 to the right place
in Column F. I realize that I can do it manually but I think it will be a
good exercise to learn SQL. After all, I always in a situation where I need
to change Jan 31 88 to 31/12/1988 and to compare two columns.
You can compare just the month and year
ColA_Date = Range("A2")
ColD_Date = Range("D2")
if month(ColA_Date) = month(ColD_Date) and _
year(ColA_Date) = year(ColD_Date) then
You can also force the date to the 1st of the month
ColA_Date = Range("A2")
FirstDay = DateSerial(year(ColA_Date), month(ColA_Date), 1)
You can also force the date to the last day of the month by going to 1st of
next month and subtracting 1 and it even works if the date is in December.
VBA thinks there are 13 months
MyDate = "12/13/09"
LastDate = DateSerial(Year(MyDate), Month(MyDate) + 1, 1) - 1
3) As for the content of Column A to D, it has already been filled with
data. I’m aware that it perhaps is too much to ask to let you write the
whole program (to fill Column F) for me, but I’m really stuck here. May I
write some codes to let you see what problem do I have from time to time,
please?
I would write the entire code for you but your wouldn't learn as much as
doing it yourself. I will help.
Thank you so much for your time and input!
--
Tatiana
:
I have lots of quetions but lets take it slow at first.
Your error message is being cause because you are trying to modify a
worksheet that is linked by a query to a database. You need to copy the data
to a new sheet to be able to modify the data. The code below will
automaticaly copy the data to an existing worksheet
Sub CopySheet()