can't get code to Run

D

dupton

Can anyone help?

I have read up on VB for Excel and written the code below in the 'Thi
workbook' module. I don't know how to make it run. I have entered i
under 'workbook activate' hoping this would be the best way to get i
to definately run.

It is the first time I have done this, hence the code, if not jus
wrong, is probably inelegant at the very least.
i am trying to scan a worksheet called 'OFF-AIR INPUT' and add up al
the values in column 'F' for all rows that have the same date in colum
'C' and the same text string "Bid-up" in column 'D' and the time i
column 'A' in HH:MM:SS is between 08:00:00 (A2) and 01:00:00 (B2).
need to do this for every day of the year (from Week1) and populat
this results in sheet 'BID-UP'.

So is the code correct and if so, how do get it to run?

:confused: dupton


Private Sub Workbook_Activate()

RCOUNT = Worksheet("OFF-AI
INPUT").ACTIVE.CELL.SpecialCells(xlLastCell).Row
CCOUNT = 7
For i = 5 To RCOUNT
For j = 3 To CCOUNT
Date = DateAdd("d", 1, "28-12-2004")
If Worksheet("OFF-AIR INPUT").Range("C5:C65536") = Date Then
If Worksheet("OFF-AIR INPUT").Range("A5:A65536")
Worksheet("OFF-AIR INPUT").Range("B2") And Worksheet("OFF-AI
INPUT").Range("A5:A65536") > Worksheet("OFF-AIR INPUT").Range("A2"
Then
If Worksheet("OFF-AIR INPUT").Range("D5:D65536") = "BID-UP
Then
Sum = Application.WorksheetFunction.Sum(Worksheet("OFF-AI
INPUT").Range("F5", Range("F5").End(xlDown)))
Worksheet("BID-UP").Cells(i, j) = Sum
End If
End If
End If
Next j
Next i

End Su
 
G

George Nicholson

If you are doing what i think you are doing (evaluating one row at a time in
a loop),
start by changing Range("A5:A65536") to either Range("A" & i) or
Cells(i,1).
As written, you are trying to evaluate the entire range each time through
the loop so the conditions are probably never met and the code doesn't
appear to run.

Change Range("C5:C65536") and Range("D5:D65536") as well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top