+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Registered User
    Join Date
    02-27-2010
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    19

    Question Copy Selected range values for few times

    Dear All,

    I am new in this forum, but i hardly to get help from others people around, hope this forum can give me some suggestions. Thanks

    Problem:
    I wish to make a marco that can let me copy 5 items for 5 times using macro automatically.

    Example:

    I got 5 alphabets from A1 to A5, A B C D E . I wish I could make duplication for these 5 alphabets using one macro by running once can get all things done.

    Expected Result:
    A1 B1

    A A
    B A
    C A
    D A
    E A
    1 B
    1 B
    1 B
    1 B
    1 B
    1 C
    1 C
    1 C
    1 C
    1 C
    Last edited by montroseite; 03-02-2010 at 10:24 AM.

  2. #2
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Excel Auto Copy Selected range values for few times

    Try this...it will create 5 items in column B for every item in column A.
    Code:
    Sub DuplicateValues()
    Dim cRange As Range
    
    Set cRange = Range("A:A").SpecialCells(xlCellTypeConstants)
    
    cRange.Copy Range("B1").Resize(cRange.Cells.Count * 5)
        
    Columns("B:B").Sort Key1:=Range("B1"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  3. #3
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Excel Auto Copy Selected range values for few times

    Thanks for the feedback. It is appreciated.

    If that takes care of your need, use the Thread Tools menu to mark the this thread as [SOLVED].
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  4. #4
    Registered User
    Join Date
    02-27-2010
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel Auto Copy Selected range values for few times

    Thanks man, this fulfill what exactly I want. However, if I wish I could re-locate those data after sorting. Any suggestions? For Example : Data start from B5 instead of B1? If this additional question should raise another thread , please do let me know, I would follow the rules. Thanks ya.

  5. #5
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Excel Auto Copy Selected range values for few times

    Maybe just add this line as the last line of code:
    Code:
    Range("B1:B4").Insert xlShiftDown   'add this
    
    End Sub
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  6. #6
    Registered User
    Join Date
    02-27-2010
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    19

    Re: Excel Auto Copy Selected range values for few times

    Erm Thanks a lot, one more last question. I already modify your code to suit my need, however I can't figure out the last part of my coding.

    Process:
    1. Raw data to be copied and duplicated in Sheet1.
    2. Counts calculation base on cell's value
    3. Relocate the data into another worksheet "Populated Data" and place at particular cells.

    Problem occur:
    4. Do data sorting on "Populated Data" worksheet, so that the outcome same as previous coding.
    5. place at particular cells. < I should do the process here.

    Do you have any idea? Thanks alot

    Code:
    Sub DuplicateValues()
    Dim cRange As Range
    Dim Counts As Integer
    
      'Raw Data at Sheet1
       Set cRange = Sheets("Sheet1").Range("A:A").SpecialCells(xlCellTypeConstants)
       
      'Duplicate base on cell's value
        Counts = Sheets("Control Panel").Range("E1").Text
    
      'Relocate the data in to Worksheet Populated Data and place at particular cells
        cRange.Copy Sheets("Populated Data").Range("C5").Resize(cRange.Cells.Count * Counts)
     
     '???  
        Sheets("Populated Data").Select
        Columns("C:C").Sort Key1:=Range("C1"), Order1:=xlAscending, Header:=xlNo, _
        OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    
    End Sub
    Last edited by montroseite; 02-27-2010 at 04:10 PM.

  7. #7
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Excel Auto Copy Selected range values for few times

    Maybe this:
    Code:
    Sub DuplicateValues()
    Dim cRange As Range
    Dim Counts As Long
    
    'Raw Data at Sheet1
       Set cRange = Sheets("Sheet1").Range("A:A").SpecialCells(xlCellTypeConstants)
       
    'Duplicate base on cell's value
        Counts = Sheets("Control Panel").Range("E1").Value
    
    'Relocate the data in to Worksheet Populated Data and place at particular cells
        cRange.Copy Sheets("Populated Data").Range("C5").Resize(cRange.Cells.Count * Counts)
     
    'Sort items so grouped items are together 
        Sheets("Populated Data").Range("C5:C" & Rows.Count).Sort Key1:=Range("C5"), _
            Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    End Sub
    Last edited by JBeaucaire; 02-28-2010 at 11:30 PM.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

  8. #8
    Registered User
    Join Date
    02-27-2010
    Location
    KL
    MS-Off Ver
    Excel 2003
    Posts
    19

    Excel Auto Copy Selected range values for few times

    Thanks a lot, I got great experience with this excel forum, Thanks ya, JBeaucaire!
    But the coding for the 4th part not working welL

    Code:
     'Sort items so grouped items are together
        Sheets("Populated Data").Columns("C5:C" & Rows.Count).sort Key1:=Range("C5"), _
            Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    It only works when i change to

    Code:
     'Sort items so grouped items are together
        Sheets("Populated Data").Columns("C:C").sort Key1:=Range("C5"), _
            Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, _
            Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
    But the result come out is not what I want @@.
    Anyway what does this coding means? Key1:=Range("C5")
    Seem like I make changes on C5 to C1 like nothing happen.
    Thanks for your suggestion and explanation in advance.
    Attached Files Attached Files
    Last edited by montroseite; 02-28-2010 at 05:58 AM. Reason: Coding not work hat fine

  9. #9
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: o Copy Selected range values for few times

    One typo in the code, corrected in post #7, try it again.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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

    Re: Copy Selected range values for few times

    Ok Thanks a lot , Things ge done . Thanks a lot

  11. #11
    Forum Guru JBeaucaire's Avatar
    Join Date
    03-21-2008
    Location
    Bakersfield, CA
    MS-Off Ver
    2010
    Posts
    18,228

    Re: Copy Selected range values for few times

    If that takes care of your need, use the Thread Tools menu to mark the this thread as [SOLVED].

    (Also, use the blue "scales" icon in our posts to leave Reputation Feedback, it is appreciated. It is found across from the "time" in each of our posts.)
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    “None of us is as good as all of us” - Ray Kroc
    “Actually, I *am* a rocket scientist.” - JB (little ones count!)

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.2.0