"Expected: list separator or )" error

ausis

New Member
Joined
Jan 12, 2011
Messages
16
Hi, i keep receiving the error noted in the thread title and i'm really confused as to why. here is my code.

Range("F4").Select
For ror02 = 1 To Sheets.Count
x = Application.WorksheetFunction.VLookup(CDate("2/01/2002"), A1:F3000, 5, False)
y = Application.WorksheetFunction.VLookup(CDate("28/02/2002"), Sheet1, 5, False)
ActiveCell.Value = (y - x) / x
ActiveCell.Offset(1, 0).Activate
Next ror02

i am trying to run a loop, to collect data through multiple worksheets to do some short calculations and have it come up on a 'master' worksheet. hopefully the problem can be resolved, thanks in advance.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
hey thanks,
it sort of works, as in there are no longer any errors*
but on the 'master' worksheet where the collected values are meant to appear, blanks shoot up.

i am searching up prices (5th column), based on dates (1st column) - just to add a bit of background, then from the prices collected, i apply a math formula to it to work out a desired ratio (% of gains)
 
Upvote 0
Try this

Code:
Sub do_math()
Dim Found As Range
Dim date1, date2
Dim a, x, y
On Error Resume Next
a = 4
date1 = CDate("02/01/2002")
date2 = CDate("28/01/2002")
For i = 1 To Sheets.Count
With Sheets(i)
x = 0
y = 0
    .Activate
Set Found = .Columns(1).Find(What:=date1, After:=.Cells(1, 1), LookIn:=xlValues)
        x = Found.Offset(0, 5).Value
Set Found = .Columns(1).Find(What:=date2, After:=.Cells(1, 1), LookIn:=xlValues)
        If Not Found Is Nothing Then
        y = Found.Offset(0, 5).Value
        a = a + 1
        End If
Sheet8.Range("F" & a) = (y - x) / x
End With
Next i
End Sub

You will need to change Sheet8 to the actual sheet you want to list the ratios on, either by code name Sheetx or by name Sheets("Sheet Name")
 
Upvote 0
sorry for the late reply,
i tried copying and pasting your code with the adjustments as needed but it still doesn't work. an error pops up at;

x = Found.Offset(0, 5).Value

the error says

"run time error; 91
object variable or with block not set"

what is causing this error?
 
Upvote 0
Hmmm, the On Error should just bypss it

try

Code:
Sub do_math()
Dim Found As Range
Dim date1, date2
Dim a, x, y
On Error Resume Next
a = 4
date1 = CDate("02/01/2002")
date2 = CDate("28/01/2002")
For i = 1 To Sheets.Count
With Sheets(i)
x = 0
y = 0
    .Activate
Set Found = .Columns(1).Find(What:=date1, After:=.Cells(1, 1), LookIn:=xlValues)
        If Not Found Is Nothing Then
            x = Found.Offset(0, 5).Value
        End If
Set Found = .Columns(1).Find(What:=date2, After:=.Cells(1, 1), LookIn:=xlValues)
        If Not Found Is Nothing Then
            y = Found.Offset(0, 5).Value
        a = a + 1
        End If
Sheet8.Range("F" & a) = (y - x) / x
End With
Next i
End Sub
 
Upvote 0
there's no error this time, but it doesn't collect the data onto the master sheet.
instead it does the calculations on each sheet, and even then, nothing comes up ;/

each sheet i have dates on the first column for each day from 2000 to 2011, and depending on the key dates specified, i wish for vba to collect the data (5column) from the keydates. i have up to 300 sheets, and 50 keydates for each sheet, so in the 'master' sheet, all the calculations are done and shown there. sorry, i hope that makes sense and helps a bit more
 
Upvote 0
also it works perfectly when i go to each sheet and type the code on the spreadsheet,
ie " =VLOOKUP((DATE(2000,7,3)),$A$1:$F$3000,5,FALSE) ", so i'm not sure where the problem could lie.
 
Upvote 0
This worked for me:

Rich (BB code):
x = Application.WorksheetFunction.VLookup(CLng(CDate("2/01/2002")), Range("A1:F3000"), 5, False)
 
Upvote 0
sorry, if you don't mind me commenting, but isn't that just the same as some of the previous suggestions? ie

"Dim Date1 As Long
Date1 = CDate(2/01/2002)"

anyhows, i tried plugging it in but it still doesn't work.

manually typing in the code on the spreadsheet then getting vba to copy it to the 'master' worksheet seems to work, so why shouldn't the codes suggested work, sigh.

where do you think the problem lies? I use excel 2007 too if that helps
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,233
Members
449,092
Latest member
SCleaveland

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