+ Reply to Thread
Results 1 to 4 of 4

Copying cells based on limited citeria

Hybrid View

  1. #1
    Registered User
    Join Date
    07-26-2011
    Location
    leicester england
    MS-Off Ver
    Excel 2007
    Posts
    20

    Copying cells based on limited citeria

    Hello

    I am trying to write a Macro that copys data from one worksheet and pastes it in the other, where it will be pasted will depend on the number of the item (as different numbers will be within two sheets) and whether or not a number has been pasted before it, if it has been pasted then the next dulipate number should be pasted into the next column across

    I Have attached a example file to make my explanasion clearer.

    thanks
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Copying cells based on limited citeria

    Hi,

    How about the date? For example you have 2 dates with number 1024 How do you want to handle that issue?

    ...
    Thank You, Mike

    Some Helpful Hints:

    1. New members please read & follow the Forum Rules
    2. Use Code Tags...Place[code]Before the first line and[/code] After the last line.
    3. If you are pleased with a solution mark your post SOLVED.
    4. Thank those who have help you by clicking the scales at the top right of the post.

    Here...

  3. #3
    Registered User
    Join Date
    07-26-2011
    Location
    leicester england
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Copying cells based on limited citeria

    well I was thinking of doing a count the defenciate between the numbers, so if the number came once, it would add it onto the first cell and so on,

    The dates and the numbers will always be different as there is a consildation function, which removes duplicate numbers and dates from the same rows,

    I know how to do it but just cant seem to write it as a VB Macro

    Thank you

  4. #4
    Valued Forum Contributor realniceguy5000's Avatar
    Join Date
    03-20-2008
    Location
    Fl
    MS-Off Ver
    Excel 2003 & 2010
    Posts
    951

    Re: Copying cells based on limited citeria

    Hi, Give This a try:

    Sub rng()
    Dim cell As Object
    Dim r As Range, rr As Range
    Dim lrow As Long
    Dim rfound As Range
    For Each wks In Worksheets
    wks.Activate
    If wks.Index > 2 Then Exit For
    lrow = Sheets(3).Cells(Rows.Count, 1).End(xlUp).Row
    Set r = Sheets(3).Range("A3:A" & lrow)
    For Each cell In r
                    
            Set rfound = wks.Cells.Find(What:=cell, After:=Range("A2"), LookIn:=xlFormulas, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False)
     
            If rfound Is Nothing Then
            
            Else
            
             
                      
            Set rr = wks.Range(Cells(rfound.Row, 3), Cells(rfound.Row, 11))
            
                For Each cel In rr
                         cel.Select
                    If Cells(cel.Row, 1).Value = vbNullString Then Exit For
                                   
                    If IsEmpty(cel) Then
                       cel.Value = cell.Offset(, 1).Value
                        cel.Offset(, 1).Value = cell.Offset(, 2).Value
                        Exit For
                    End If
                    
                Next cel
               
          
            
            
            End If
      
        
    10
    Next cell
    Next wks
    End Sub
    Here is a test book as well

    ...
    Attached Files Attached Files

+ 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