+ Reply to Thread
Results 1 to 5 of 5

Using 'Range' in VBA/VBE Office 2007 Excel

  1. #1
    Registered User
    Join Date
    07-19-2010
    Location
    cle, ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Using 'Range' in VBA/VBE Office 2007 Excel

    This is becoming more than confusing. I am reading from the Book "Excel 2007 Bible".
    -
    Copying a range
    Copying a range is a frequent activity in macros. When you turn on the macro recorder (using absolute recording mode) and copy a range from A1:A5 to B1:B5, you get a VBA macro like this:
    Sub CopyRange()
    Range(“A1:A5”).Select
    Selection.Copy
    Range(“B1”).Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    End Sub

    Once pasted and run the above recorded macro, that I copied and pasted works fine

    From the book: "This macro works, but it’s not the most efficient way to copy a range. You can accomplish exactly the same result with the following one-line macro:"

    ''''' The following code fails miserably:

    Sub CopyRange2()
    Range(“A1:A5”).Copy Range(“B1”)
    End Sub

    Once pasted/typed in to the VBE, the entire line which begins with 'Range', between the 'Sub' and 'End Sub' lines, turns red. Obviously, for me, the code does not do what the author states. Is this code correct or do I have an issue with the VBE?

    Allow me to assure you all, my copy and paste skills are second to none. :>)

    I'm trying to learn by example(s) supposedly specific to my version of Excel, but when I run it to items such as I am posting here, well; it just takes my breath away. In other words, how the Sam Hill could this happen!

  2. #2
    Forum Contributor
    Join Date
    03-11-2010
    Location
    India
    MS-Off Ver
    2010
    Posts
    268

    Re: Using 'Range' in VBA/VBE Office 2007 Excel

    Problem seems to be with your double quotes. Looks like a copy-paste problem after all .
    Just re-type / replace the the double quotes after pasting, or type the line instead of pasting, and it will work.

    hth
    Ajay

  3. #3
    Valued Forum Contributor
    Join Date
    06-17-2009
    Location
    Chennai,India
    MS-Off Ver
    Excel 2003,excel 2007
    Posts
    678

    Re: Using 'Range' in VBA/VBE Office 2007 Excel

    how did you get the double quotes-what key did you use. Those seem to be non printable SPECIAL characters and not regular double quotes. ( I use an addin called "hexcharts" to find the character code). retype using double quotes which key is normally in the second row from bottom of the key board left to the right hand side enter key
    what is the keyboard you use.

    I am giving an example of code

    Sub CopyRange2()
    Range("a1:A5").Copy Range("B1")------this line is ok in black.
    Range(“A1:A5”).Copy Range(“B1”)-------this is in red . This line is copied from your code.
    End Sub

    retype again the line

  4. #4
    Registered User
    Join Date
    07-19-2010
    Location
    cle, ohio
    MS-Off Ver
    Excel 2007
    Posts
    3

    Re: Using 'Range' in VBA/VBE Office 2007 Excel

    Thank you both. As previously stated, "my copy and paste skills are second to none" --meaning-- I copied it just as it was. Hence, I either have a problem with copy -and paste from a PDF or the char's used in the PDF are not true double-quotes.

    Thank you again.
    Last edited by teylyn; 08-03-2010 at 12:10 AM. Reason: removed spurious quote

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Using 'Range' in VBA/VBE Office 2007 Excel

    245 & venkat

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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