#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 204
Default 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   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,203
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code to send email to address within selection in Excel workbook vic1 Excel Discussion (Misc queries) 3 May 28th 08 09:51 PM
Copy Selection - Transpose Selection - Delete Selection Uninvisible Excel Discussion (Misc queries) 2 October 23rd 07 04:18 PM
TIP: Dynamic chart selection without code Dermot Charts and Charting in Excel 0 August 11th 06 08:23 AM
Running code on a drop down selection change Steve Haack Excel Worksheet Functions 1 April 26th 05 05:03 AM
limit cell list selection based on the selection of another list lorraine Excel Worksheet Functions 2 December 14th 04 08:17 PM


All times are GMT +1. The time now is 11:47 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"