Macro to automatically delete row with data with specfic criteria II

Referring to previous similar question, this macro should also be able to do the same action for any active file as stated in the previous question.
ceneiqeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Glenn RayExcel VBA DeveloperCommented:
Your previous question had different processing rules for two files:

2. Example if 50 is selected, then whatever data found in Row 50 (from Column C to Column GE) should be deleted EXCEPT for
- column AB in file "V.xls"
 - column CF and column CG in file "W.xls"

Which rule do you want applied in this case?  Or do you have a new rule for files other than "V" and "W" that you want incorporated into that question's solution?
0
ceneiqeAuthor Commented:
I have bold the new rules as follows:

To create a macro to automatically delete data in a specific row where the row is a variable.

It should do the following:
1. Dialog box to pop up " Enter row number"
OK | Cancel

2. Example if 50 is selected, then whatever data found in Row 50 (from Column C to Column GE) should be deleted EXCEPT for
- column AB in file "V.xls"
- column CF and column CG in file "W.xls"

NOTE: The file can be any active file, not just "V.xls" or "W.xls" file.

3. Once done, pop up dialog "Completed - Data in cell xx: yy, etc - deleted."
OK


Example if cell E50, G50, O50 has data, then they should be deleted.
If Data in cell E50 = 10, G50=20, O50=30, then the message should read:
 

"Completed - Data in E50=10, G50=20, O50=30 - deleted"

if no data in that specific row, then "Completed - no data found"
0
Glenn RayExcel VBA DeveloperCommented:
This code will remove data from cells in a selected row between columns C:GE - with the exceptions for V and W files - and report the cells and values removed:
Option Explicit
Sub Remove_Row_Data()
    Dim lngRow As Long
    Dim strWkbkName, strDelList As String
    Dim c As Integer
    
    strWkbkName = ActiveWorkbook.Name
    On Error Resume Next
    lngRow = InputBox("Enter row number", "Remove Row Data")
    If IsNumeric(lngRow) = True And (lngRow > 0) Then
        Select Case strWkbkName
            Case "V.xls"
                For c = 3 To 187
                    If c <> 28 Then
                        If Cells(lngRow, c).Value <> "" Then
                            strDelList = strDelList & Cells(lngRow, c).Address & _
                                         ": " & Cells(lngRow, c).Value & ", "
                            Cells(lngRow, c).ClearContents
                        End If
                    End If
                Next c
            Case "W.xls"
                For c = 3 To 187
                    If c <> 84 And c <> 85 Then
                        If Cells(lngRow, c).Value <> "" Then
                            strDelList = strDelList & Cells(lngRow, c).Address & _
                                         ": " & Cells(lngRow, c).Value & ", "
                            Cells(lngRow, c).ClearContents
                        End If
                    End If
                Next c
            Case Else
                For c = 3 To 187
                    If Cells(lngRow, c).Value <> "" Then
                            strDelList = strDelList & Cells(lngRow, c).Address & _
                                         ": " & Cells(lngRow, c).Value & ", "
                        Cells(lngRow, c).ClearContents
                    End If
                Next c
        End Select
        If strDelList <> "" Then
            strDelList = Left(strDelList, Len(strDelList) - 2)
            MsgBox "Completed - Data in " & strDelList & " - deleted."
        Else
            MsgBox "Completed - no data found."
        End If
    End If
End Sub

Open in new window


Example workbook attached.

Regards,
-Glenn
EE-Q-28531864.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

ceneiqeAuthor Commented:
thks, works but not the exceptions in V.xls and W.xls.

Example if 50 is selected, then whatever data found in Row 50 (from Column C to Column GE) should be deleted EXCEPT for
- column AB in file "V.xls"
- column CF and column CG in file "W.xls"

When i tested "V.xls" file and "W.xls"file, column AB in V.xls and Column CF and CG data in W.xls are being deleted. This should not be the case. the data should stay as mentioned above.
0
Glenn RayExcel VBA DeveloperCommented:
Works for me.

1) Open the macro-enabled workbook from above.
2) Open either "V.xls" or "W.xls"
3) Call up the macro dialog by pressing [Alt]+[F8]
4) Select "All open workbooks" from the "Macros in" droplist and then locate "Remove_Row_Data" from the list on top (it may actually say "EE_Q_28531864.xlsm!Remove_Row_Data").
5) Click the "Run" button.
6) Enter the row number to clear.

In my test files, it follows your instructions - excluding AB in "V.xls" and excluding CF:CG in "W.xls".  If you file names are any different, it won't work.

I'm attaching my test files for your reference.

-Glenn
V.xls
W.xls
0
ceneiqeAuthor Commented:
Thanks ! Yes it is working now.
Sorry i forgot to rename the file name back to the original name in the macro code.
0
ceneiqeAuthor Commented:
expert was very fast, detailed and systematic.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.