+ Reply to Thread
Results 1 to 17 of 17

Compare data and delete cell

  1. #1
    Registered User
    Join Date
    01-31-2006
    Posts
    14

    Unhappy Compare data and delete cell

    Hello All,
    This is my problem which is probably simple but I am still have trouble understanding VBA.
    In column "A" I have truck numbers and am adding to that list continously. In column "O" I have a list of truck numbers that reflects my inventory. What I would like to do is, check column "A" against column "O" and if the number exist in "A" then just delete the number out of the cell in "O".
    I hope this makes sense, if it doesn't this is probably why I can't figure it out. If you need me to provide actual numbers I can. Thanks in advance for all the help. In fact you guys have helped me in the past and are great. Thanks again!

  2. #2
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Maybe this will help you out

    Sub find_sheet()
    rowcount = Cells(Cells.Rows.Count, "o").End(xlUp).Row
    For i = 2 To rowcount 'start second row because there is a heater
    Range("o" & i).Select
    val_to_check = ActiveCell.Value
    'find value
    Range("a1").Select
    Cells.Find(What:=val_to_check, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    verif = ActiveCell.Value
    'verify if value was found
    'Column A header is named Trunk
    If verif = "Trunk" Then
    MsgBox val_to_check & " Trunk number is not present in colum A but is in column O"
    GoTo line1:
    End If
    Range("o1").Select
    'find value in column o and delete
    Cells.Find(What:=val_to_check, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    verif1 = ActiveCell.Value
    'Column O header is named Trunk
    If verif1 = "Trunk" Then
    GoTo line1:
    Else
    ActiveCell.ClearContents
    End If
    line1:
    Next
    End Sub
    Last edited by jetted; 09-21-2006 at 03:03 PM.

  3. #3
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Jetted,
    Thanks for the help you have given me, I pasted it in my excel sheet and ran it. What it does is delete all of column "O" whether or not the truck number is in column "A". Any suggestions. Thanks

  4. #4
    Forum Contributor
    Join Date
    11-11-2005
    Posts
    267
    try and effect these changes:

    Cells.Find(What:=val_to_check, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate


    SearchOrder:=xlByColumns -------->SearchOrder:=xlByRows
    If your cells DO NOT contain formulas:
    LookIn:=xlFormulas----------->LookIn:=xlValues
    HTH
    Myles

    ...constantly looking for the smoother pebble while the whole ocean of truth lies before me.

  5. #5
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi NasCarDJ

    I have amended the code in my previous email. Try it out and let me know.

    THanks
    Denis

  6. #6
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    try this
    Please Login or Register  to view this content.
    VBA - The Power Behind the Grid

    Posting a sample of your workbook makes it easier to look at the Issue.

  7. #7
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Hello All,
    Thx for all the help but none of the codes work so far. Jetted, I tried the new code but still just deletes all the cells. The other codes didn't seem to do anything. Am I doing something wrong. Would it be better if I put the numbers on? Thx again all I really do appreciate it.
    James

  8. #8
    Forum Contributor stevebriz's Avatar
    Join Date
    09-07-2006
    Location
    Santiago Chile
    Posts
    389
    Can you post you xls or email it to me to look and see if we can find the problem?

  9. #9
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Steve,
    Thanks for your interest in helping me. Been a bad weekend and just now am able to look at answers. I will try to put this on for you by the weekend. Whenever you get to it. Thanks for the help. James

  10. #10
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Steve,
    I tried to upload my xls file but it said file type error. I don't have a zip program. Any suggestions on how I can upload this file for you? Thanks for your help
    James

  11. #11
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    If your document is less then 100.0 KB change the extension from xls to txt. Then when we will download your file we will revert to original extension.

    or
    Upload your file to this location http://www.mega-file.net/, just change the extension to jpg.

    Hope this help.
    Denis

  12. #12
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Jetted,
    Thank you for the help I will do that with the next post

  13. #13
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Steve and Jetted,
    Attached hopefully is the file. Column A has the truck numbers that I am keeping, Column O has my inventory. I need the number deleted from O if it is in A. Thanks
    Attached Files Attached Files

  14. #14
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi

    Try this code

    Sub find_sheet()
    'add column to get value of column A
    Columns("B:B").Select
    Selection.Insert Shift:=xlToRight
    Columns("A:A").Select
    Selection.Copy
    Range("B1").Select
    Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
    False, Transpose:=False
    Range("B1").Select

    rowcount = Cells(Cells.Rows.Count, "p").End(xlUp).Row
    For i = 2 To rowcount 'start second row because there is a heater
    Range("p" & i).Select
    val_to_check = ActiveCell.Value
    'find value
    Range("b1").Select
    Cells.Find(What:=val_to_check, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    verif = ActiveCell.Address(rowabsolute, columnabsolute)
    'verify if value was found
    'Column A header is named Trunk
    If verif = "P" & i Then
    'MsgBox val_to_check & " Trunk number is not present in colum A but is in column O"
    GoTo line1:
    End If
    Range("p1").Select
    'find value in column o and delete
    Cells.Find(What:=val_to_check, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
    :=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
    False).Activate
    verif1 = ActiveCell.Value
    'Column O header is named Trunk
    If verif1 = "Trunk" Then
    GoTo line1:
    Else
    ActiveCell.ClearContents
    End If
    line1:
    Next
    'clean up
    Columns("B:B").Select
    Selection.Delete Shift:=xlToLeft
    Range("A2").Select
    End Sub
    Last edited by jetted; 10-11-2006 at 07:21 AM.

  15. #15
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Hello Jetted,
    Thank you oh so much. That is great and works good. I don't mind the message box but if there was a way to delete that and just have it check all the way thru that would be better but it works for me and evenually I would not have that much in inventory anyway. Again thank you so much.
    James

  16. #16
    Valued Forum Contributor
    Join Date
    12-16-2004
    Location
    Canada, Quebec
    Posts
    363
    Hi James

    I have just amend my previous post to deactivate the message box.
    I am glad to see everything worked out.

    Denis

  17. #17
    Registered User
    Join Date
    01-31-2006
    Posts
    14
    Jetted,
    Sorry it's been a couple weeks, been very busy, thanks for the amendment it works great just what I wanted to do. I have happy people now. Thx again.
    James

+ 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