Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default format cells

I have this code below, in which I am trying to format cells with different
formats, is there a way of shortening this and maybe the change will make it
run faster.
These are sub heading that are suppose to be printed per produt info.

Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());

rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string0";
LastRow++;
LastRow++;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());
rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string1";

rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 35;
rg.Value2 = "string2";

rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing);
rg.ColumnWidth = 35;
rg.WrapText = false;
rg.Value2 = "string3";

rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string4";

rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string5";

rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 11;
rg.Value2 = "string6";

rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 9;
rg.Value2 = "string7";
  #2   Report Post  
Posted to microsoft.public.excel.programming
ADG ADG is offline
external usenet poster
 
Posts: 76
Default format cells

Hi Pamish

Can only suggest using a with statement to speed execution once you have set
the range. e.g.

with rg
.Font.Bold = true;
.Font.Name = "Arial";
.Font.Size = 9;
.Cells.RowHeight = 30;
end with

P.S. What does LastRow++ do?
--
Tony Green


"Pamish" wrote:

I have this code below, in which I am trying to format cells with different
formats, is there a way of shortening this and maybe the change will make it
run faster.
These are sub heading that are suppose to be printed per produt info.

Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());

rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string0";
LastRow++;
LastRow++;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());
rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string1";

rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 35;
rg.Value2 = "string2";

rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing);
rg.ColumnWidth = 35;
rg.WrapText = false;
rg.Value2 = "string3";

rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string4";

rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string5";

rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 11;
rg.Value2 = "string6";

rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 9;
rg.Value2 = "string7";

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default format cells

I am writing the program in c#, using Excel application to run my reports,
LastRow++ is telling it to go to the next row i.e if LastRow = 4, then after
LastRow++, LastRow will be 5.
The cells have got different formats ie. columnwidth, size, fontsize, etc.

"ADG" wrote:

Hi Pamish

Can only suggest using a with statement to speed execution once you have set
the range. e.g.

with rg
.Font.Bold = true;
.Font.Name = "Arial";
.Font.Size = 9;
.Cells.RowHeight = 30;
end with

P.S. What does LastRow++ do?
--
Tony Green


"Pamish" wrote:

I have this code below, in which I am trying to format cells with different
formats, is there a way of shortening this and maybe the change will make it
run faster.
These are sub heading that are suppose to be printed per produt info.

Range rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());

rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string0";
LastRow++;
LastRow++;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), "I" +
LastRow.ToString());
rg.Font.Bold = true;
rg.Font.Name = "Arial";
rg.Font.Size = 9;
rg.Cells.RowHeight = 30;

rg = oWorkSheet.get_Range("A" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string1";

rg = oWorkSheet.get_Range("B" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 35;
rg.Value2 = "string2";

rg = oWorkSheet.get_Range("C" + LastRow.ToString(), Type.Missing);
rg.ColumnWidth = 35;
rg.WrapText = false;
rg.Value2 = "string3";

rg = oWorkSheet.get_Range("D" + LastRow.ToString(), Type.Missing);
rg.WrapText = true;
rg.Value2 = "string4";

rg = oWorkSheet.get_Range("E" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.Value2 = "string5";

rg = oWorkSheet.get_Range("F" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 11;
rg.Value2 = "string6";

rg = oWorkSheet.get_Range("G" + LastRow.ToString(), Type.Missing);
rg.WrapText = false;
rg.ColumnWidth = 9;
rg.Value2 = "string7";

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
Excel 2007 format cells to date format Stefan Excel Discussion (Misc queries) 0 June 1st 10 09:06 PM
How to format cells in Excel 2007 (i.e. currency format)? DonR Excel Discussion (Misc queries) 2 May 25th 08 11:16 PM
how do i format a cell based on format of a range of cells? Chris Hardick Excel Discussion (Misc queries) 2 April 3rd 06 08:54 AM
want format cells alignment not format cells font style Jeannie Bean Excel Discussion (Misc queries) 2 February 10th 06 09:31 AM
Cells won't convert to number format, even after format/cells/num. scottr Excel Discussion (Misc queries) 5 April 12th 05 11:02 PM


All times are GMT +1. The time now is 01:05 AM.

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

About Us

"It's about Microsoft Excel"