+ Reply to Thread
Results 1 to 5 of 5

Thread: A better way than copy - paste ?

  1. #1
    Registered User
    Join Date
    10-21-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2003
    Posts
    25

    A better way than copy - paste ?

    Hello

    I have a bit of codestring containing a copy and paste function, but I would love not to have to use copy - paste function.

    The Goal (cooked a bit down):
    I have two columns (part of a larger worksheet) one with material numbers and one with description (name) of the material.

    For example like this:

    Material # Material name
    45 Text1
    23 Text2
    65 Text3
    89 Text4
    45 Text1
    23 Text2
    65 Text3
    89 Text4
    45 Text1
    23 Text2
    65 Text3
    89 Text4
    - -
    And it continous down

    I want to identify when the same materialnumber as the first one, appears in the columns again. And then copy the material numbers and descriptions from the first time the materialnumber appears until the second time it appears.

    So that i in another Sheet ie. Sheet2 gets the result:

    45 Text1
    23 Text2
    65 Text3
    89 Text4

    I have coded the following:

    Sub Group_Rawmaterials()
        
    Dim RowVar1 As Long
    Dim Value1 As Long
        
        Sheets("Sheet1").Select
        Value1 = Range("F2")
        
        RowVar1 = Cells.Find(What:=Value1, After:=[F2], SearchOrder:=xlByColumns, SearchDirection:=xlNext).Row
        
        RowVar1 = RowVar1 - 1
            
        Range("F2", "G" & RowVar1).Select
        Selection.Copy
        Sheets("Sheet2").Select
        Range("A2").Select
        ActiveSheet.Paste
    End Sub
    The question now is, can this be done without the copy paste function?

    I thank you in advance.

    /Freakazoid
    Last edited by Freakazoid; 10-22-2010 at 07:07 AM.

  2. #2
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: A better way than copy - paste ?

    Try this
    Sub Group_Rawmaterials()
        
    Dim RowVar1 As Long
    Dim Value1 As Long
        
        With Sheets("Sheet2")
        Value1 = .Range("F2").Value
        RowVar1 = .Cells.Find(What:=Value1, After:=[F2], SearchOrder:=xlByColumns, SearchDirection:=xlNext).Row - 1
            
        .Range("F2", "G" & RowVar1).Copy Sheets("Sheet3").Range("A2")
        End With
    End Sub
    Last edited by royUK; 10-22-2010 at 06:57 AM.
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  3. #3
    Forum Moderator DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Suffolk, UK
    MS-Off Ver
    2002, 2007 & 2010
    Posts
    21,423

    Re: A better way than copy - paste ?

    another alternative might be:

    Dim rngC As Range
    With Sheets("Sheet1")
        Set rngC = .Range(.Cells(2, "F"), .Cells.Find(.Cells(2, "F"), .Cells(2, "F"), , , xlByColumns, xlNext).Offset(-1))
    End With
    Sheets("Sheet2").Cells(2, "A").Resize(rngC.Rows.Count).Value = rngC.Value

  4. #4
    Registered User
    Join Date
    10-21-2010
    Location
    Copenhagen
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: A better way than copy - paste ?

    It works briliantly and with a lot less computing effort.

    Thanks alot guys, I absolutely love to be able ask a question and get the answer when you return from lunch.

    /Freakazoid

  5. #5
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639

    Re: A better way than copy - paste ?

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

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