Hi,
I am stuch with this problem,What I want is a VBA code against the button "Delete" in the sheet "Metal" that,
if in the sheet "Face" the value in the column AL is 0 then the entire row will be deleted in the "Metal" sheet.
The values in Column J in "Face" and Column F in the sheet "Metal" is unique.That is Test1,Test2,Test3 etc..
I am uploading a dummy sheet for reference.
Thanks in advance.
Last edited by fatalcore; 02-14-2012 at 04:41 AM.
So should the values in column J in "Face" and column F in "Metal" be matched and then the value in column AL checked and then the corresponding row in Sheet Metal to be deleted?
Cheers,
Arlette
If I helped, Don't forget to add to my reputation (click on the star below the post)
Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
Use code tags when posting your VBA code: [code] Your code here [/code]
Hi arlu1201,
Yes, you are absolutely right about it. If the value in AL = 0 then only the row in Sheet "Metal" will be deleted.
Thanks in advance.
Hello fatalcore,
Here is the code for the two macros that appear in the attached workbook.
Command Button Code
Private Sub CommandButton2_Click() Dim Cell As Range Dim Rng As Range Set Rng = Worksheets("Face").Range("AL20, AL22, AL24") Application.ScreenUpdating = False For Each Cell In Rng If Cell = 0 Then Call FindThenDeleteRow(Rng.Parent.Cells(Cell.Row, "J").Text) End If Next Cell Application.ScreenUpdating = True End Sub
Module1 Code to Delete the Rows
Sub FindThenDeleteRow(ByVal Text As String) Dim Cell As Range Dim Rng As Range Set Rng = Worksheets("Metal").Range("E9").CurrentRegion Set Cell = Rng.Find("test2", , xlValues, xlWhole, xlByRows, xlNext, False) If Not Cell Is Nothing Then Cell.MergeArea.EntireRow.Delete End If End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Hi,Leith Ross
Thanks for your reply, can u please modify the code a little bit so that the range is not fixed like test2 only. I want it for Test1, Test2 and Test3 also.
Thanks in advance.
Hello fatalcore,
Sorry, I forgot to remove "test2" from the Find operation. The value to find is passed in as as string. The code should be as below...
Sub FindThenDeleteRow(ByVal Text As String) Dim Cell As Range Dim Rng As Range Set Rng = Worksheets("Metal").Range("E9").CurrentRegion Set Cell = Rng.Find(Text, , xlValues, xlWhole, xlByRows, xlNext, False) If Not Cell Is Nothing Then Cell.MergeArea.EntireRow.Delete End If End Sub
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Starbelow the post.
3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Thanks mate![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks