+ Reply to Thread
Results 1 to 33 of 33

It's stopped working

  1. #1
    Registered User
    Join Date
    01-03-2007
    Posts
    26

    It's stopped working

    I have a code... and I am trying to use it with a different file.

    The files is set up the same, the code has been unedited, but it's not working

    Sub findAndReplace()
    Dim ws1 As Worksheet
    Dim ws2 As Worksheet
    Dim searchFor As String
    Dim searchCol As Range

    Set ws1 = Sheets("SBK") 'sheet for which we look in column A
    Set ws2 = Sheets("Sheet1") 'sheet we try to match with column E

    'last row on the sheet with the updated information
    lastRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
    'column E on sheet we are going to update
    Set searchCol = ws2.Columns(5)

    'work with one row at a time; i is the row number
    For i = 1 To lastRow
    'read the entry in column A for this row
    searchFor = ws1.Range("A" & i)
    'attempt to find a match
    matchRow = 0
    On Error Resume Next
    matchRow = Application.WorksheetFunction.Match(searchFor, searchCol, 0)
    If matchRow > 0 Then
    'if we got here, we found a match
    ws2.Range("D" & matchRow) = ws1.Range("D" & i)
    ws2.Range("E" & matchRow) = ws1.Range("E" & i)
    ws2.Range("F" & matchRow) = ws1.Range("F" & i)
    ws2.Range("G" & matchRow) = ws1.Range("G" & i)
    End If
    Next i

    End Sub


    What it should do:
    I want it to look in SBK at column A and match it to column E of Sheet1. Then copy collumns DEFG from SBK to DEFG of sheet1.... Is there some reason it's not doing it?

  2. #2
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Are you getting an error message? Or is simply nothing happening?

    How do you run the macro? Hot-key? Button? Macros dialog?

  3. #3
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Note: Someone on here made it for me, and I was so greatful. It worked the once, but after that it does nothing.

  4. #4
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    No, my mouse is a hourglass for about three minutes then when it goes off nothing...

    I start it running by hitting alt+f8 then run.

  5. #5
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Yes, it looks familiar ...

    Are you getting an error message? Or is simply nothing happening?

    How do you run the macro? Hot-key? Button? Macros dialog?

  6. #6
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by mikhailia
    Note: Someone on here made it for me, and I was so greatful. It worked the once, but after that it does nothing.
    do you have all numeric data that you are now trying to match?

    try some alpha, the

    On Error Resume Next
    matchRow = Application.WorksheetFunction.Match(searchFor, searchCol, 0)
    If matchRow > 0 Then


    hides that numerics fail.

    hth
    ---
    Si fractum non sit, noli id reficere.

  7. #7
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Would it be possible for you to upload the workbook?

    If it freezes for that long, I think there must be many thousands of rows of data?

  8. #8
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    It should match two numbers and then I want it to paste a text and some numbers.

    I am not very good with this program so the last bit of this confuses me. Do you mean it all needs to be numeric?

  9. #9
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Quote Originally Posted by MSP77079
    Would it be possible for you to upload the workbook?

    If it freezes for that long, I think there must be many thousands of rows of data?
    I can't upload it... The company I am doing this for said I can seek help but I can't give anyone the actual thing...

    By the way there are 29827 rows of data....

  10. #10
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Do you mean it all needs to be numeric?
    I think Bryan meant the opposite. It should NOT be numeric.

  11. #11
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Is the match you are looking for an EXACT match? In other words, when searching for "ABC", would "ABCD" be considered a match, or not a match?

  12. #12
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    What format should it be in? I know how to format cells if nothing else... I actually know a lot aout excel... except the programing...

    And the first time I used the code I put up there, I had almost double that mant rows.
    and it should be an exact match. There are no comments or anything on the cells either. So that won't hurt it.

  13. #13
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    If you have numbers, try formatting as text.

  14. #14
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Ok, testing it... be back in four or so minutes

  15. #15
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Ok, Nothing still. Not even an error message.
    Last edited by mikhailia; 01-21-2007 at 09:37 PM.

  16. #16
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    I think you are going to have to "walk" through the code and find out where the problem is.

    I would put a break-point in a the line:
    Please Login or Register  to view this content.
    See that "searchFor" is what you expected. Do you have a row where you KNOW there should be a match found? If so, you can put in code like this:
    Please Login or Register  to view this content.
    (where 1234 is the row number where you know there should be a match) and but a breakpoint on the MsgBox ... then, the code will run down to that row before hitting the breakpoint.

  17. #17
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by mikhailia
    I can't upload it... The company I am doing this for said I can seek help but I can't give anyone the actual thing...

    By the way there are 29827 rows of data....
    if you can copy 5 rows of column E from Sheet1, (just 5 cells) and 5 cells of column A from sheet RBK (where at least two match the data from column E) that should help.

    If these are names (of clients) they can be disguised to protect your data.

    ---
    plus just a small question, column E of Sheet1 is the Match column, but is overwritten, is this what should happen?
    ---
    Last edited by Bryan Hessey; 01-21-2007 at 09:57 PM.

  18. #18
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    I got the message that it can't run in breakpoint mode... I don't know what that means but I bet it is important.

    5 rows I can do... I'll upload it to you send it, and give the link directly to the people that need it. I don't want just anyone downloading it.

  19. #19
    Forum Contributor
    Join Date
    03-13-2005
    Posts
    6,195
    Quote Originally Posted by mikhailia
    I got the message that it can't run in breakpoint mode... I don't know what that means but I bet it is important.

    5 rows I can do... I'll upload it to you send it, and give the link directly to the people that need it. I don't want just anyone downloading it.
    pm it to MSP77079

  20. #20
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Sorry for having a stick up my *** and being so picky about sending it around. I sent the small file/link to MSP77079

  21. #21
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Oh sorry I forgot to say, if there is no match it should be left blank. I really appreciate your all's help because without it I would be copying and pasting 28000 things by hand.

  22. #22
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Got it. There's no code in it, though. I'll take the code you posted earlier today.

  23. #23
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Quote Originally Posted by MSP77079
    Got it. There's no code in it, though. I'll take the code you posted earlier today.
    I put the code on there... Do you have to save it a special way? Because if you do, I don't know how to do it... I saved it in notepad after using it. xD

  24. #24
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Did not need the code. Problem is that on SBK there is:
    01013
    01020

    On Sheet1 there is:
    1013
    1020

    These do not match.

  25. #25
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    but it doesn't do anything even on exact matches... The numbers get bigger in the end and all but 8000 would be exact... Those were some of the early ones. I am sure that helps though. its like

    0xxxx
    0xxxx
    0xxxx
    0xxxx
    1xxxx
    1xxxx

    and they keep getting bigger, in the end it matches up


    I will go through and fix those.

  26. #26
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    OK ... but, I still think the essence of the problem is numbers vs. text. The leading 0 being dropped is a good indication of that.

    So, I'll work on that issue. Just wanted to confirm.

  27. #27
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    Thank you.

    I am going to test it with all of them being zipcode format... since it would be 5 numbers auto.
    The test failed spectacularly
    Last edited by mikhailia; 01-21-2007 at 10:23 PM.

  28. #28
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Yep. that was the problem. Try this:

    Please Login or Register  to view this content.
    the only problem with this code is that it will match
    01234 with 1234.

    If all of the stuff in column A / E is the same length then, that's OK. If not, I should do another test. I.e., if it is numeric, then it has to satisfy 2 criteria:
    1. the match works
    2. the cell entries are the same length

    Hmmm. good idea. I'll do that now.

  29. #29
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    OK ... so, this works, and you need to decide if you want to use it or not.

    If you want 01013 to match with 1013, then use the code I posted a few minutes ago. If you DO NOT want 01013 to match with 1013 then add the modification below:

    Please Login or Register  to view this content.

  30. #30
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    i felt it rude to not reply, but it is still running. I think it froze completely. I have to go check. Thank you for all your help so far.

    Yeah it was froze. I am going to leave it to run all night without touching it... because it only freezes if I do something. So I will update the happenings of it tommorow.
    Last edited by mikhailia; 01-21-2007 at 10:56 PM.

  31. #31
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Thanks for the feedback. I'll check in the morning.

  32. #32
    Registered User
    Join Date
    01-03-2007
    Posts
    26
    It worked! Thank you very much!!! <3<3<3<3

    I couldn't reply in the morning, I had to go to school

  33. #33
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Thanks for the feedback. You have your priorities right.

+ 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