XL 2013 find numbers in sheet1 and delete specific columns from row with corresponding number on sheet3

fmoaveni

New Member
Joined
Nov 23, 2015
Messages
38
Hi,
First off I would like to say thank you very much for any help that I can get. This is my first time posting to this forum and I hope I can give it enough detail to get some help.

Version: excel 2013

I am having trouble writing a vba code for this and I have looked all over the Internet but cannot seem to find what I need. I have tried modifying different codes for hours as well.
The specific range from is from sheet1 in a workbook (L24 : L60)
I want it to search every row in the sheet called "Eingeben". It is a german workbook but the codes are all in english so far.
From the "Eingeben" sheet (it is technically sheet3 but I have changed the name), if it has a number in column C, I want to automatically delete from that row...columns a,b,e,f,g,h,i.

Example:
Cell L24 on Sheet1 contains 300001
Cell C208 on the Eingeben sheet contains the same 300001 number. It will then delete from the Eingeben sheet A208, B208, E208, F208, G208, H208, and I208. (I want whatever number...in this case 300001 to stay in column C cell 208....This column must always remain constant).

I want it to look at the entire range though from L24:L60 and check the entire Eingeben sheet (column C) against this criteria.

Is that possible?

Thank you again in advance!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Anyone have any ideas? I am not sure how else to clarify so if it is confusing maybe someone could ask a question so I can elaborate?
 
Upvote 0
Try:
Code:
Sub ClearCells()
    Application.ScreenUpdating = False
    Dim Num As Range
    Dim foundNum As Range
    Dim sAddr As String
    For Each Num In Sheets("Sheet1").Range("L24:L60")
        With Sheets("Eingeben").Range("C:C")
            Set foundNum = .Find(Num, LookIn:=xlValues, lookat:=xlWhole)
            If Not foundNum Is Nothing Then
                sAddr = foundNum.Address
                Do
                    Sheets("Eingeben").Range("A" & foundNum.Row).Resize(, 2).ClearContents
                    Sheets("Eingeben").Range("E" & foundNum.Row).Resize(, 5).ClearContents
                    Set foundNum = .FindNext(foundNum)
                Loop While foundNum.Address <> sAddr
                sAddr = ""
            End If
        End With
        Set foundVal = Nothing
    Next Num
    Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Hi mumps,
Thank you very much for your help. This is going to make a huge difference. The macro works so well but it took about 5 mins to execute. Is that to be expected or can I set a range on it so it only looks at maybe the first 5000 rows?
 
Upvote 0
Using your example of searching for the number 300001 in column C, can there be more than one occurrence of the number in column C or is it a unique value in column C?
 
Upvote 0
Hi mumps,
The 300001 should be a constant. That number is an example for a space in a warehouse and should never change. That is why I never want it deleted. It should just be unique, however, it may end up having 300001a and 300001b in the future. Will that be a problem?
 
Upvote 0
Since the number is unique with the possibility of having an "a" or "b" or any other letters attached, this macro should be faster and also take into account the addition of letters to the number.
Code:
Sub ClearCells()
    Application.ScreenUpdating = False
    Dim Num As Range
    Dim foundNum As Range
    For Each Num In Sheets("Sheet1").Range("L24:L60")
        Set foundNum = Sheets("Eingeben").Range("C:C").Find(Num, LookIn:=xlValues, lookat:=xlPart)
        If Not foundNum Is Nothing Then
            Sheets("Eingeben").Range("A" & foundNum.Row).Resize(, 2).ClearContents
            Sheets("Eingeben").Range("E" & foundNum.Row).Resize(, 5).ClearContents
        End If
    Next Num
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
mumps,
You are a hero! That works so well! Thank you very much. I am posting another question in a new thread if you have some time. It may be a little more complicated if you think you are up for the challenge :)
It has to do with a pop up box I have created to input information on the "Eingeben" tab. Thank you!
 
Upvote 0
You are very welcome. :) Send me a private message with the link to your new thread and I'll have a look.
 
Upvote 0

Forum statistics

Threads
1,214,914
Messages
6,122,211
Members
449,074
Latest member
cancansova

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top