ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   can't get code to Run (https://www.excelbanter.com/excel-programming/304611-cant-get-code-run.html)

dupton

can't get code to Run
 
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

--
Message posted from http://www.ExcelForum.com


George Nicholson[_2_]

can't get code to Run
 
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.

--
George Nicholson

Remove 'Junk' from return address.


"dupton " wrote in message
...
Can anyone help?

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

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


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 12:28 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com