Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it
is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#2
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
As long as your sure your row/column coordinates are correct then try this
LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#3
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
Mike
Thanks for that. In the interim I had thought that maybe my dim statements for the lastlap and lapcol were wrong. I deleted the dim statement altogether for those 2 and then it seemed to work. How should they be set. "Mike H" wrote: As long as your sure your row/column coordinates are correct then try this LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#4
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
Hi,
Ridercell is a range so Dim ridercell as range Lapcol is a row number so dim as long Dim LapCol as long What I didn't post in my reply is how I tested this and did so by setting up some variables like this Dim LapCol As Long, RiderCell As Range LapCol = 1 Set RiderCell = Range("a1") LastLap = Format(Sheets("A Grade").Cells(RiderCell.Row, LapCol).Value, "hh:mm.ss") So with a time of 00:00:10 in A1 it correctly returned 00:00.10 Mike "NDBC" wrote: Mike Thanks for that. In the interim I had thought that maybe my dim statements for the lastlap and lapcol were wrong. I deleted the dim statement altogether for those 2 and then it seemed to work. How should they be set. "Mike H" wrote: As long as your sure your row/column coordinates are correct then try this LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#5
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
Kudos to you for using DIM statements before using variables in your code.
Very good programming practice that will help prevent typographic errors from causing problems you may not easily detect. You can 'force' yourself to do this by setting the "Require Variable Declaration" option under Tools -- Options in the VB Editor itself. This will automatically add an Option Explicit statement at the very beginning of all new code modules. If you have not been doing that, you can add that statement as the first line to existing modules to get the same results. "NDBC" wrote: Mike Thanks for that. In the interim I had thought that maybe my dim statements for the lastlap and lapcol were wrong. I deleted the dim statement altogether for those 2 and then it seemed to work. How should they be set. "Mike H" wrote: As long as your sure your row/column coordinates are correct then try this LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#6
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
JL, I apologise for not realising the importance of this advice earlier. At
the time I was too wrapped up in solving my immediate problems. It is only after a month of working on this and going back over all my questions to ensure I have not forgotten anything that I should have learnt that I can appreciate what you told me. To any new time programmers, make sure you follow the advice about the DIM statements. It may seem like a pain at first but it will pay dividends in the long run. "JLatham" wrote: Kudos to you for using DIM statements before using variables in your code. Very good programming practice that will help prevent typographic errors from causing problems you may not easily detect. You can 'force' yourself to do this by setting the "Require Variable Declaration" option under Tools -- Options in the VB Editor itself. This will automatically add an Option Explicit statement at the very beginning of all new code modules. If you have not been doing that, you can add that statement as the first line to existing modules to get the same results. "NDBC" wrote: Mike Thanks for that. In the interim I had thought that maybe my dim statements for the lastlap and lapcol were wrong. I deleted the dim statement altogether for those 2 and then it seemed to work. How should they be set. "Mike H" wrote: As long as your sure your row/column coordinates are correct then try this LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
#7
Posted to microsoft.public.excel.misc
|
|||
|
|||
cell selection code
A lot of people think this means you have to think EVERYthing out in advance,
and it does not. To do so would basically require you to first write a requirements specification followed by a design specification and then on into coding. Other than for large, formalized efforts, that's just not going to happen. You can get into code and suddenly realize you need a new variable (or even constant) and declare it right then and there, in line with your code. I sometimes do that, BUT before leaving the module, I'll take any DIM statements I created late in the game like that and put them near the top of the module where they can all reside together and be found easily. For global or 'Public' variables and constants, I often create a single module that I typically name Declarations and put all of those into it. Again, so that they can be found easily come code maintenance or enhancement time. Next advice is to actually write MEANINGFUL comments for future reference. Don't restate the obvious: X = X+1 ' add one to X doesn't do much for you 6 months down the road, the code tells you that you're adding 1 to X. The thing you'll want to know is WHY and WHAT FOR: X = X+1 ' increment pointer into address array to look at next entry might be a bit more helpful later in the life of your application. "NDBC" wrote: JL, I apologise for not realising the importance of this advice earlier. At the time I was too wrapped up in solving my immediate problems. It is only after a month of working on this and going back over all my questions to ensure I have not forgotten anything that I should have learnt that I can appreciate what you told me. To any new time programmers, make sure you follow the advice about the DIM statements. It may seem like a pain at first but it will pay dividends in the long run. "JLatham" wrote: Kudos to you for using DIM statements before using variables in your code. Very good programming practice that will help prevent typographic errors from causing problems you may not easily detect. You can 'force' yourself to do this by setting the "Require Variable Declaration" option under Tools -- Options in the VB Editor itself. This will automatically add an Option Explicit statement at the very beginning of all new code modules. If you have not been doing that, you can add that statement as the first line to existing modules to get the same results. "NDBC" wrote: Mike Thanks for that. In the interim I had thought that maybe my dim statements for the lastlap and lapcol were wrong. I deleted the dim statement altogether for those 2 and then it seemed to work. How should they be set. "Mike H" wrote: As long as your sure your row/column coordinates are correct then try this LastLap = Format(Sheets("A Grade").Cells(ridercell.Row, lapcol).Value, "hh:mm.ss") Mike "NDBC" wrote: I am trying to get the time (lastlap) from Worksheet (A Grade) when i know it is located in the nth column (lapcol) and the nth row ridercell.row. I have checked that the row and column co-ordinates are right but I don't think this code works. It is returning 0 when it should have been the time 0:00:10. Is it something to do with the number being in a time format. LastLap = Sheets("A Grade").Cells(riderCell.Row, LapCol).Value Thanks again |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Code to send email to address within selection in Excel workbook | Excel Discussion (Misc queries) | |||
Copy Selection - Transpose Selection - Delete Selection | Excel Discussion (Misc queries) | |||
TIP: Dynamic chart selection without code | Charts and Charting in Excel | |||
Running code on a drop down selection change | Excel Worksheet Functions | |||
limit cell list selection based on the selection of another list | Excel Worksheet Functions |