Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 148
Default How to combine lines of code?

I currently have multiple situations where code resembles the following:

Range("a" & numberrows + 1).Select
Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"
Selection.NumberFormat = "m/d/yyyy"

In order to reduce the size and complexity, I would like to be able to
condense some of the coding to resemble something like:

Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"; NumberFormat =
"m/d/yyyy"

I thought this was possible but my attempts to play with syntax have been
unsuccessful in getting it to work.

Any help would be much appreciated.
TIA


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default How to combine lines of code?

It can't be done in one line, but it can be cleaned up a little...

With Range("a" & numberrows + 1)
.Formula = "=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"
.NumberFormat = "m/d/yyyy"
end with

Note this no longer selects the cell so if you require the active cell to
move then you will need to add a

..select

in the with clause

HTH


"Papa Jonah" wrote:

I currently have multiple situations where code resembles the following:

Range("a" & numberrows + 1).Select
Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"
Selection.NumberFormat = "m/d/yyyy"

In order to reduce the size and complexity, I would like to be able to
condense some of the coding to resemble something like:

Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"; NumberFormat =
"m/d/yyyy"

I thought this was possible but my attempts to play with syntax have been
unsuccessful in getting it to work.

Any help would be much appreciated.
TIA


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default How to combine lines of code?

Papa,
You can use a ":" to write more than statement on a line, but this usually
does not help readability.
As Jim indicated, use of With and also object variables make coding clearer.

NickHK

"Papa Jonah" wrote in message
...
I currently have multiple situations where code resembles the following:

Range("a" & numberrows + 1).Select
Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))"
Selection.NumberFormat = "m/d/yyyy"

In order to reduce the size and complexity, I would like to be able to
condense some of the coding to resemble something like:

Range("a" & numberrows + 1).Formula =
"=date(YEAR(begrevdate)+1,month(begrevdate),day(be grevdate))";

NumberFormat =
"m/d/yyyy"

I thought this was possible but my attempts to play with syntax have been
unsuccessful in getting it to work.

Any help would be much appreciated.
TIA




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
Combine and fill Names & Addresses in 2 lines? clubchamp04 Excel Discussion (Misc queries) 2 March 13th 08 12:59 AM
Combine stacked column and line chart w/series lines ancillaries Charts and Charting in Excel 1 April 7th 06 11:51 PM
"how to combine multiple lines into a pull down option?" eric_mc2 Excel Worksheet Functions 1 July 4th 05 03:06 AM
Want to combine columns and horizontal lines in complex chart - Can it be Done?! James Hobart Charts and Charting in Excel 3 February 18th 05 02:23 AM
Combine Code Steph[_3_] Excel Programming 2 January 23rd 04 08:19 PM


All times are GMT +1. The time now is 02:12 PM.

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"