Last cell touched on sheet

C

cupboy

What can I do to have the last cell touched on the sheet saved using code?
The code below does not retain B37 as the last cell even though this code is
right at the end before saving the workbook. Instead the last cell touched is
retained as the last one the user clicked on ... which is very annoying and
messy looking. Thanks.

excel.Range rg37 = null;
rg37.get_Range("B37", "B37");
rg37.Font.ColorIndex =
clsStatic.ColorCodes.white;
rg37.Value2 = dtRunDate.ToShortDateString();
rg37.Select();
 
J

Jim Cone

What programming language are you using?
What version of Excel are you using?
Where is the code located?
--
Jim Cone
Portland, Oregon USA



"cupboy" <[email protected]>
wrote in message
What can I do to have the last cell touched on the sheet saved using code?
The code below does not retain B37 as the last cell even though this code is
right at the end before saving the workbook. Instead the last cell touched is
retained as the last one the user clicked on ... which is very annoying and
messy looking. Thanks.

excel.Range rg37 = null;
rg37.get_Range("B37", "B37");
rg37.Font.ColorIndex = clsStatic.ColorCodes.white;
rg37.Value2 = dtRunDate.ToShortDateString();
rg37.Select();
 
C

cupboy

It's Visual C# and excel object library 11. Code is located in Utah.
It fails on the Select() but gives no useful info. I've also tried Activate().
Just give me VBA code and I'll convert it over to what I use.
 
P

Peter T

Just give me VBA code and I'll convert it over to what I use.

Why not give us the VBA code that fails, if necessary with any other steps
required to replicate.

Regards,
Peter T
 
C

cupboy

Here is the corrected code. I had to Activate the sheet first, before I could
do the Select. That's all that was wrong with it.

excel.Range rg37 = w.get_Range("B37", "B37");
rg37.Font.ColorIndex = clsStatic.ColorCodes.white;
rg37.Value2 = dtRunDate.ToShortDateString();
w.Activate();
rg37.Select(); // 'Can't select unless the sheet
is active
// refer to
http://msdn.microsoft.com/en-us/library/bb178282.aspx
 

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