+ Reply to Thread
Results 1 to 12 of 12

Delete the same specific row in two worksheets

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    16

    Delete the same specific row in two worksheets

    Hi,

    I am trying to create a macro that will be able to select a UPC code from the "Daily Usage" Sheet and correspond it to the same UPC code from the "Total Data" Sheet and delete them both and move them both up (no blank spaces). Here is what I have so far. I tried to correspond it by trying to compare the Time Value, but I found out that the time value will be off by 1 second sometimes because it takes a little time for it to be scanned on "Daily Usage" and copied/pasted to the "Total Data" (I created a macro for that already)

    Sub Delete()
        Dim xScreenUpdating As Boolean
        Dim DailyUsedUPC As Range
        Dim UsedUPC As Range
        Dim xTxt As String
        
        On Error Resume Next
        xTxt = ActiveWindow.RangeSelection.Address
        Set DailyUsedUPC = Application.InputBox("Select UPC code to delete", "Delete UPC", xTxt, , , , , 8)
        
        If DailyUsedUPC Is Nothing Then
        MsgBox "Canceled"
    
        
        DailyUsedUPC.Delete Shift:=xlUp
        Sheets("Used").Select
    
        
      End If
        Application.ScreenUpdating = xScreenUpdating
    
        
    End Sub
    Edit: I also forgot to mention that I don't want it to be cell referenced directly because the "Daily Usage" Sheet will be cleared every day while the "Total Data" sheet won't be. I just want to have the option to delete a UPC code from both sheets in case a worker accidentally scans something twice.
    Attached Files Attached Files
    Last edited by Cygneous; 09-10-2020 at 11:20 AM.

  2. #2
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: Delete the same specific row in two worksheets

    Why not just incorporate code that does not allow the same item to be scanned twice...

    Anyway...try this...
    Sub Delete()
    Dim X, DailyUsedUPC As Range, xTxt As String
    xTxt = ActiveWindow.RangeSelection.Address
    Set DailyUsedUPC = Application.InputBox("Select UPC code to delete", "Delete UPC", xTxt, , , , , 8)
    If Not DailyUsedUPC Is Nothing Then
        With Sheets("Total Data")
            X = Application.Match(DailyUsedUPC, .Range("A:A"), 0)
            If Not IsError(X) Then .Range("A" & X).EntireRow.Delete
        End With
    Else
        MsgBox "Canceled"
    End If
    End Sub
    Last edited by Sintek; 09-10-2020 at 11:30 AM.
    Good Luck...
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the [★ Add Reputation] to left of post window...
    Also....Add a comment if you like!!!!
    And remember...Mark Thread as Solved...
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    08-28-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    16

    Re: Delete the same specific row in two worksheets

    Some will have to be scanned multiple times because we have multiple of the same materials all the time. The thing is that sometimes a worker will accidentally something twice (or something wrong entirely) that they are not suppose to and it will mess up the inventory count.

  4. #4
    Registered User
    Join Date
    08-28-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    16

    Re: Delete the same specific row in two worksheets

    Quote Originally Posted by sintek View Post
    Why not just incorporate code that does not allow the same item to be scanned twice...

    Anyway...try this...
    Sub Delete()
    Dim X, DailyUsedUPC As Range, xTxt As String
    xTxt = ActiveWindow.RangeSelection.Address
    Set DailyUsedUPC = Application.InputBox("Select UPC code to delete", "Delete UPC", xTxt, , , , , 8)
    If Not DailyUsedUPC Is Nothing Then
        With Sheets("Total Data")
            X = Application.Match(DailyUsedUPC, .Range("A:A"), 0)
            If Not IsError(X) Then .Range("A" & X).EntireRow.Delete
        End With
    Else
        MsgBox "Canceled"
    End If
    End Sub
    I think I can work with this! Thank you so much for the help! :D

  5. #5
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: Delete the same specific row in two worksheets

    ..........................
    THANKS.gif

  6. #6
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: Delete the same specific row in two worksheets

    Only just realised you want it delete off both sheets...
    Add red snippet...
    With Sheets("Total Data")
        X = Application.Match(DailyUsedUPC, .Range("A:A"), 0)
        If Not IsError(X) Then .Range("A" & X).EntireRow.Delete
    End With
    DailyUsedUPC.EntireRow.Delete

  7. #7
    Forum Guru Sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,520

    Re: Delete the same specific row in two worksheets

    If Not IsError(X) Then .Range("A" & X & ":F" & X).Delete

  8. #8
    Registered User
    Join Date
    08-28-2020
    Location
    US
    MS-Off Ver
    2016
    Posts
    16

    Re: Delete the same specific row in two worksheets

    Just wondering if there is a quick way to delete a row from column A to F instead of the entire row

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Macro to delete Worksheets that don't contain a specific pattern
    By Brawnystaff in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-08-2020, 03:44 PM
  2. VBA to delete worksheets except one specific sheet
    By winmaxservices in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-13-2015, 08:15 AM
  3. [SOLVED] Delete all blanks rows in specific range on all worksheets
    By Dumy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 01-01-2015, 03:06 PM
  4. VBA loop to insert and delete worksheets in a specific sheet within a list
    By supppy in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-09-2014, 09:02 PM
  5. [SOLVED] Delete specific row for all worksheets
    By lorena ferraz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-27-2014, 10:44 AM
  6. How to delete entire row if first cell of it is empty for specific range and worksheets
    By roshanvmech in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-01-2014, 12:36 PM
  7. [SOLVED] Macro to delete all worksheets except for one with specific name
    By jaimealvarez in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-25-2012, 12:01 PM

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