PDA

View Full Version : Show todate as default



VaMu
05-16-2007, 06:37 AM
Hello,

I am new here and know nearly nothing about VBA. I am trying to make an attendance/absent system for a school. It is quite complicated, because we have six periods, 40 teachers, over 400 pupils, which can belong to several groups at the same time. Several teachers teach the same group during the day. Teachers want to know the attendance data of their indivicual courses, and management wants to sum all up. So, I should use Access, for example...

Anyway, now I am trying rather "simple" solution (which leads to large files I'm afraid):
First I have the Main workbook, all data summed up: names of all the students are in column A, they can belong to five different groups (next five columns). To the right all the absent data is summed from other workbooks, which have the same structure, except that these other workbooks are for individual teachers, and they have ten worksheets, at the maximum, for their courses per period, that is six weeks.

For selecting/showing the correct group of pupils Auto Filter is used. I have to copy every 400 names to ten worksheets, for example, and there must be the same autofilter on, in every sheet. The file size is 1,2 MB so far, not too bad, yet.

But then there should be dates in columns. Perhaps not for the whole year (only 255 columns in Excel 2003?), but at least for three periods, weekends should be excluded. Dates should be in reverse order, passed date to the right.

My problem: it is going to be a large table. When a teacher activates a spreadsheet (that he/she has renamed, I do not know the name beforehand), today's date/column should be selected/activated automatically as the first column after column, say G. The window is split vertically after column F. For example, if in cell AZ5 reads 16.5.2007, the code should start from G5, for example, and compare today's value until it reaches AZ5, which is the same. Cell AZ5 should be selected and column AZ the first one shown to the right of window split. Could you help me? We are using Excel 2003 at school.

By the way, I have to sum up hours, which should be categorized: sick, sleepy etc... and calculate percentages... perhaps I should give up... probably the file size would be enormous.

Simon Lloyd
05-16-2007, 07:24 AM
Thats a hell of a post just to ask how to lookup a value on the same row!
if you want to find todays date after column G how about

Cells.Find(What:=Date, After:=ActiveSheet.Range("F1"), LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
with the find method you do not need to match todays date in column G then move across the row to find it as this will find and activate it!

mdmackillop
05-16-2007, 12:42 PM
Hi VaMu,
Welcome to VBAX
Paste this into the Worksheet module. It looks for today's date in row 5. It should be set up with FreezePanes rather than Split (see sample)
Private Sub Worksheet_Activate()
Dim Fmt As String, Col As Long
Fmt = Range("G5").NumberFormat
Col = ActiveSheet.Rows(5).Find(What:=Format(Date, Fmt), LookIn:=xlValues).Column
ActiveWindow.ScrollColumn = Col
End Sub

Simon Lloyd
05-16-2007, 02:31 PM
Malcom, i think his G5 was an example, i think in column G he has a list of dates for the year and then in one of the cells in the same row to the right the same date will appear!

Would the find method i supplied not do that? any feedback would be nice.

mdmackillop
05-16-2007, 02:41 PM
Hi Simon,
I understood dates are in a row, and he wants to set the opening view to the current date.

Your code may find the date, but it depends on formatting. See here (http://www.ozgrid.com/VBA/find-dates.htm).
Also, you may not always want to go to the date cell in row 5 or whatever, if you're working in row 500 for example.

Simon Lloyd
05-16-2007, 02:44 PM
Thanks Malcom, is that "May find" a definate find? LOL, joking aside i understand your logic.

mdmackillop
05-16-2007, 02:51 PM
Does your code work in my sample?

Simon Lloyd
05-16-2007, 02:57 PM
only if i change xlFormula to xlvalues!

VaMu
05-16-2007, 11:18 PM
Hello,

Thank you very much for your very fast help! Sorry about my long message. Yes, I want to have the dates on row 5, for example, in reverse order, to show as many passed days to the right as possible without scrolling. And the default column should be today's column, even if the autofilter starts with visible rows from row 500 (rows 1-499 are hidden). I want to keep the columns as narrow as possible, so I would show only the day digit, i.e. in today's column there would be only 17 (17th of May).

Unfortunately, I do not have time now to make an example workbook (I would like to use ISO week numbers also in row 4, for example), but I tried Splitdate.xls at home in Excel 2007, and I got the error:

Run-time error '91':

Object variable or With block variable not set

I wonder, isn't my problem a very common one (I do not mean this run-time error)?

Thank you again for your help!

Simon Lloyd
05-17-2007, 02:10 AM
try changing XlFormula to xlValues

mdmackillop
05-18-2007, 12:53 PM
Try this version

VaMu
05-21-2007, 12:11 AM
SplitDate.xls seems to work with the right date format. I could live with it, if I could turn the dates counter clockwise as vertical -90 degrees, and thus get the columns as narrow as possible. But after this change, the macro does not work automatically, when I open the spreadsheet. It works, if I run the macro manually. Attached is my version.

VaMu
05-22-2007, 02:07 AM
I have to remove Office 2007 from my home computer, and reinstall Office 2003. Macros are not working. Recommendation: leave 2003, if you want to play with 2007. Comparison of 2003 and 2007:

add-ins.com/Excel%202003%20versus%202007.htm

About my macro: I will try to hide the row 5, and copy only the day of the month in row 6, thus keeping the date format functional in row 5, but get narrow columns. I hope the macro works, even if it shows ## in row 5 and is hidden.

VaMu
05-22-2007, 02:08 AM
I have to remove Office 2007 from my home computer, and reinstall Office 2003. Macros are not working. Recommendation: leave 2003, if you want to play with 2007. Comparison of 2003 and 2007:

add-ins.com/Excel%202003%20versus%202007.htm

(Add www)

About my macro: I will try to hide the row 5, and copy only the day of the month in row 6, thus keeping the date format functional in row 5, but get narrow columns. I hope the macro works, even if it shows ## in row 5 and is hidden.

mdmackillop
05-22-2007, 11:12 PM
Hi Vamu,
You can show only the day/ month etc by formating the cell as "d" or "mmm"

VaMu
05-24-2007, 01:33 AM
Thank you very much, mdmackillop! The code is working with datevalues in cells, but now I would like to have a formula linking to another workbook, thus I could change the date range in one place. I have some 40 workbooks for each teacher, now I have to change the date range for each manually. Would this be possible?

I even managed to add a macro so that the find works also on workbook open.