+ Reply to Thread
Results 1 to 33 of 33

It's stopped working

Hybrid View

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

  9. #9
    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.

  10. #10
    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?

  11. #11
    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.

  12. #12
    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?

  13. #13
    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.

+ 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