473,320 Members | 1,823 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,320 software developers and data experts.

Excel-Macros-Loops #2

Hi All New to Forum,

Need a little help with my script if you could any one can help.
I have created a script to look for dates. current date and past 5 dates.
the script only works if the dates are in row "C" how do I change the script to reflect all rows in the excel document.

When it loops it skips records that don't reflect past 5 days and current date.
when I run the cscript excel.vbs where it reads the skiped records it leaves a gap between records.
how to fix???

here is the script:

Option Explicit

Dim objExcel
Dim excelPath
Dim worksheetCount
Dim counter
Dim currentWorkSheet
Dim usedColumnsCount
Dim usedRowsCount
Dim row
Dim column
Dim top
Dim left
Dim Cells
Dim curCol
Dim curRow
Dim word
Rem current date & Record
Dim dCurrent
Dim dRecord

WScript.Echo "Reading Data from " & excelPath
excelPath = "C:\VBTest\Book2.xls"
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = 1
objExcel.Workbooks.open excelPath, false, true
workSheetCount = objExcel.Worksheets.Count
WScript.Echo "We have " & workSheetCount & " worksheets"
For counter = 1 to workSheetCount
WScript.Echo "-----------------------------------------------"
WScript.Echo "Reading data from worksheet " & counter & vbCRLF
Set currentWorkSheet = objExcel.ActiveWorkbook.Worksheets(counter)
usedColumnsCount = currentWorkSheet.UsedRange.Columns.Count
usedRowsCount = currentWorkSheet.UsedRange.Rows.Count
top = currentWorksheet.UsedRange.Row
left = currentWorksheet.UsedRange.Column
Set Cells = currentWorksheet.Cells
For row = 0 to (usedRowsCount -1)

dCurrent = date ()
dRecord = Cells(row+top,3).value
if DateDiff("d", dCurrent, dRecord) >= -5 And DateDiff("d", dCurrent, dRecord) <= 0 then
For column = 0 to usedColumnsCount-1
curRow = row+top
curCol = column+left
word = Cells(curRow,curCol).Value
WScript.Echo Word
Next

end if

WScript.Echo
rem WScript.Echo (Date)
Next

Set currentWorkSheet = Nothing
Next

objExcel.Workbooks(1).Close
objExcel.Quit
Set currentWorkSheet = Nothing
Set objExcel = Nothing



Thanks
Mike
Nov 9 '06 #1
1 1822
willakawill
1,646 1GB
dRecord = Cells(row+top,3).value
Hi Mike,
You have this set to column C (3). i.e.
Cells(Row, Col)

You mention row C but there is no such row. Only a column

Hope this helps
Nov 9 '06 #2

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

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
3
by: Otie | last post by:
I found the following under the GetObject help notes and in the example for GetObject: "This example uses the GetObject function to get a reference to a specific Microsoft Excel worksheet...
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#...
14
by: pmud | last post by:
Hi, I need to use an Excel Sheet in ASP.NET application so that the users can enter (copy, paste ) large number of rows in this Excel Sheet. Also, Whatever the USER ENETRS needs to go to the...
22
by: Howard Kaikow | last post by:
There's a significant problem in automating Excel from VB .NET. Reminds me of a problem I encountered almost 3 years ago that was caused by the Norton Auntie Virus Office plug-in. Can anybody...
9
by: Anthony | last post by:
To me, creating Excel 2003 spreadsheets programmatically via VB.NET hasn't really changed since the days of VB6. That is, I'd do something similar to this Code: Dim ExcelApp As...
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...
16
by: alexia.bee | last post by:
Hi all, In some weird reason, excel instance won;t die if i remove the comment from 4 lines of setting values into struct. here is a snipcode public...
9
by: Doug Glancy | last post by:
I got the following code from Francesco Balena's site, for disposing of Com objects: Sub SetNothing(Of T)(ByRef obj As T) ' Dispose of the object if possible If obj IsNot Nothing AndAlso...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.