+ Reply to Thread
Results 1 to 3 of 3

How to combine lines of code?

  1. #1
    Papa Jonah
    Guest

    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(begrevdate))"
    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(begrevdate))"; 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. #2
    Jim Thomlinson
    Guest

    RE: 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(begrevdate))"
    .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(begrevdate))"
    > 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(begrevdate))"; 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. #3
    NickHK
    Guest

    Re: 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" <[email protected]> wrote in message
    news:[email protected]...
    > 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(begrevdate))"
    > 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(begrevdate))";

    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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1