+ Reply to Thread
Results 1 to 3 of 3

Custom change Macro's Range value, from cells input.

Hybrid View

  1. #1
    Registered User
    Join Date
    10-09-2009
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    42

    Custom change Macro's Range value, from cells input.

    The code below works fine, I can copy selected area into new sheet. However, I wish to custom change the Range("A1:AO164") value, for example, at cells(1,1) I key in A1, then cells(1.2) I key in A56, then this changes will reflect to the value in this macro to Range("A1:A56").
    I tried using this way :

    Dim A as string
    cells(1,1).text = a
    cells(1,2).text = b
    Range("a:b").Select

    However, this silly act not working, please help me on this issue, I already run out of idea ~!

    <script type="text/javascript">
    
    Sub Macro1()
     
        Range("A1:AO164").Select
        Selection.Copy
        Sheets("july09").Select
        Sheets.Add
        ActiveSheet.Paste
    End Sub
    
    </script>
    Last edited by Kenji; 10-18-2009 at 12:38 AM.

  2. #2
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    Win10/MSO2016
    Posts
    12,963

    Re: Custom change Macro's Range value, from cells input.

    'alway use option explicit to ensure all variables are declared
    'and used correctly (that is with the correct data types as declared
    Option Explicit
    Sub test()
        
        'Declare two variables to hold the values in cells A1 and b1
        Dim A As String, B As String
        
        'Copy the contents of the two worksheet cells into the two variables
        'Note that what ever is in cell A1 gets loaded into variable A, etc.
        
        A = Range("A1").Value
        B = Range("B1").Value
        
        'select the new range
        Range(A & ":" & B).Select
    End Sub
    Note also that cells(1,1).text = a should be cells(1,1).Value = a
    BUT: That line would have replaced the contents of Cell A1 with whatever was in variable A.
    In this case A is empty, thus it would have erased the contents of A1!

    Also note that A = Range("A1").Value is read:
    (let) the contents of var A get what's in cell A1.
    But your original said:
    (let) cell A1 get the value stored in var A (it was empty)
    Last edited by protonLeah; 10-17-2009 at 09:40 PM. Reason: slight clarification
    Ben Van Johnson

  3. #3
    Registered User
    Join Date
    10-09-2009
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: Custom change Macro's Range value, from cells input.

    It is work well.
    Thanks a lot ~!!! But I can't find blue button to rate you !@@

+ 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