+ Reply to Thread
Results 1 to 4 of 4

revise macro to use cell reference

Hybrid View

adnan buran revise macro to use cell... 04-26-2005, 05:00 AM
Leith Ross Hello Adnan, Add a string... 04-26-2005, 05:42 AM
adnan buran Hello Leith, Thank you... 04-26-2005, 09:18 AM
Leith Ross Hello Adnan, What is in... 04-26-2005, 09:44 AM
  1. #1
    Registered User
    Join Date
    12-20-2004
    Posts
    29

    revise macro to use cell reference

    hi all,


    I have the code below:


    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 15/01/2004
    '

    Workbooks.Open Filename:= "Book2.xls"
    Range("A:B").Copy Destination:=Workbooks("Book1").Range("A:B")
    Windows("Book2.xls").Close
    MsgBox ("Completed Copying")
    End Sub


    I want to revise this macro, so that instead of Range(A:B), it will get the range from a cell (let's say from A1). So if the value in A1 is E:F, then range E:F is copied ..etc

    many thanks,
    Last edited by adnan buran; 04-26-2005 at 05:03 AM.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Adnan,

    Add a string variable to hold the new range address. I've added into the macro for you.

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 15/01/2004
    '


    Dim NewRng As String

    Workbooks.Open Filename:= "Book2.xls"
    NewRange = Range("A1").Value
    Range(NewRange).Copy Destination:=Workbooks("Book1").Range(NewRange)
    Windows("Book2.xls").Close
    MsgBox ("Completed Copying")
    End Sub


    Sincerely,
    Leith Ross

  3. #3
    Registered User
    Join Date
    12-20-2004
    Posts
    29
    Quote Originally Posted by Leith Ross
    Hello Adnan,

    Add a string variable to hold the new range address. I've added into the macro for you.

    Sub Macro1()
    '
    ' Macro1 Macro
    ' Macro recorded 15/01/2004
    '


    Dim NewRng As String

    Workbooks.Open Filename:= "Book2.xls"
    NewRange = Range("A1").Value
    Range(NewRange).Copy Destination:=Workbooks("Book1").Range(NewRange)
    Windows("Book2.xls").Close
    MsgBox ("Completed Copying")
    End Sub


    Sincerely,
    Leith Ross

    Hello Leith,

    Thank you very much for the help. I copied this code and run, but it gives the error message;
    "Object doesn't support this property or method" at line "Range(NewRange)...Range(NewRange). Did I do anything wrong?

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Adnan,

    What is in cell "A1"? Do you have a range address like "E:F"? If so, you will need to add rows to that address like "E10:F50".

    Let me know,
    Leith Ross

+ 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