+ Reply to Thread
Results 1 to 16 of 16

copy paste code correction

Hybrid View

yiannis1925 copy paste code correction 12-13-2011, 09:51 AM
TMS Re: copy paste code correction 12-13-2011, 10:28 AM
nilem Re: copy paste code correction 12-13-2011, 11:09 AM
yiannis1925 Re: copy paste code correction 12-13-2011, 12:11 PM
yiannis1925 Re: copy paste code correction 12-20-2011, 09:05 AM
nilem Re: copy paste code correction 12-20-2011, 09:44 AM
yiannis1925 Re: copy paste code correction 12-20-2011, 10:02 AM
yiannis1925 Re: copy paste code correction 01-16-2012, 12:16 PM
yiannis1925 Re: copy paste code correction 01-17-2012, 04:37 AM
nilem Re: copy paste code correction 01-17-2012, 09:47 AM
yiannis1925 Re: copy paste code correction 01-17-2012, 01:01 PM
yiannis1925 Re: copy paste code correction 01-24-2012, 06:19 AM
nilem Re: copy paste code correction 01-24-2012, 08:26 AM
yiannis1925 Re: copy paste code correction 01-30-2012, 04:49 AM
nilem Re: copy paste code correction 02-01-2012, 10:41 AM
yiannis1925 Re: copy paste code correction 02-06-2012, 10:19 AM
  1. #1
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    copy paste code correction

    Hello I need a code to locate a word from column C in column A and then copy-> paste colums B,C,D,E to the rows were these words were located.

    Please see attached an example file with a macro code that i'm using currently, the problem is that when working with a file of 100000 entries, this is very slow

    copy_paste_new.xlsm


    Need your help..
    Last edited by yiannis1925; 12-13-2011 at 12:11 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,557

    Re: copy paste code correction

    You could try the following code.

    Note that it uses columns AA and AB as temporary staorage for the contents of column A, without and with a leading space. Change range if necessary

    Regards, TMS


    'add a leading space to the search term to allow for full word filter
    Range("A2:A" & Range("A" & Rows.Count).End(xlUp).Row).Copy Range("AA2")
    Range("AB2:AB" & Range("AA" & Rows.Count).End(xlUp).Row).Formula = "="" "" & AA2"
    Range("AB2:AB" & Range("AA" & Rows.Count).End(xlUp).Row).Copy
    Range("A2").PasteSpecial xlPasteValues
    
    ' :
    ' : your code 
    ' :
      
    'remove leading space from the search term to allow for full word filter
    Range("AA2:AA" & Range("A" & Rows.Count).End(xlUp).Row).Copy Range("A2")
    Range("AA2:AB" & Range("A" & Rows.Count).End(xlUp).Row).EntireColumn.Delete
    
    End Sub
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: copy paste code correction

    Another option. The 'acropole' and 'Acropole' - the same thing, right?
    Attached Files Attached Files

  4. #4
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Quote Originally Posted by nilem View Post
    Another option. The 'acropole' and 'Acropole' - the same thing, right?
    Simply magic! this works excellent!

  5. #5
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Hello,

    I would like to make one change to that code if it is possible.

    When it is executed, I want to copy-paste to only the one that are blank... we can set the column B as a check point...

    so if the cell is blank there it should copy-paste there...
    if not, then it should do nothing with it.

    I hope it is easy to understand what I mean...

    Thank you in advance...

  6. #6
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: copy paste code correction

    try this
    Sub ertert()
    Dim x, i&, j&, s: Application.ScreenUpdating = False
    x = Range("A1:E" & Cells(Rows.Count, 1).End(xlUp).Row).Value
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            If Len(x(i, 3)) Then .Item(Trim(x(i, 3))) = Array(x(i, 2), x(i, 3), x(i, 4), x(i, 5))
        Next i
    
        For i = 1 To UBound(x)
            If Len(Trim(x(i, 2))) = 0 Then 'new line
                s = Split(x(i, 1))
                For j = 0 To UBound(s)
                    If .Exists(Trim(s(j))) Then Cells(i, 2).Resize(, 4).Value = .Item(Trim(s(j))): Exit For
                Next j
            End If
        Next i
    End With: Application.ScreenUpdating = True
    End Sub

  7. #7
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Perfect! thank you

  8. #8
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Hello,

    is it possible to make one change... ?

    The above code, searches for only one keyword... but if i have a phrase in column C this will not detect it.

    Please see an example attached! run the below code in it

    Sub ertert()
    Dim x, i&, j&, s: Application.ScreenUpdating = False
    x = Range("A1:E" & Cells(Rows.Count, 1).End(xlUp).Row).Value
    With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 1 To UBound(x)
            If Len(x(i, 3)) Then .Item(Trim(x(i, 3))) = Array(x(i, 2), x(i, 3), x(i, 4), x(i, 5))
        Next i
    
        For i = 1 To UBound(x)
            If Len(Trim(x(i, 2))) = 0 Then 'new line
                s = Split(x(i, 1))
                For j = 0 To UBound(s)
                    If .Exists(Trim(s(j))) Then Cells(i, 2).Resize(, 4).Value = .Item(Trim(s(j))): Exit For
                Next j
            End If
        Next i
    End With: Application.ScreenUpdating = True
    End Sub
    Thank you for your help.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    wrong file attached... here is the correct one
    Attached Files Attached Files

  10. #10
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: copy paste code correction

    see attachment
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    excellent! thank you!

  12. #12
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Hello,

    the problem that I see now, is that if I have a small word for example "niki" it will detect it in "Thessaloniki" ...

    so, with the old code we didn't had the above problem but if we had a phrase "hotels in thessaloniki" we couldn't detect it...
    and with the new one, we can detect a phrase but have the above problem

    is it possible to combine the two and have a perfect result ?

    thank you!

  13. #13
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: copy paste code correction

    maybe so (see attached file)
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    Hello,

    I would like to know, if it is possible to make the code a little bit more advanced.
    In the attached file you will see an example...

    Thank you
    Attached Files Attached Files

  15. #15
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: copy paste code correction

    Hi, Yiannis. Check it out.
    Attached Files Attached Files

  16. #16
    Registered User
    Join Date
    11-14-2011
    Location
    Dusseldorf, Germany
    MS-Off Ver
    Excel 2003
    Posts
    97

    Re: copy paste code correction

    I made a change in the code... from

    If Len(x(i, 3)) Then
    to

    If Len(x(i, 3)) And Len(x(i, 4)) Then
    because I need to check only for Negative Elements where B,C,D and E are with data.

    The problem is that now, if we have data only in B and C for some reason they are being deleted... see in attached file.
    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