Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Macro to automatically delete row with data with specfic criteria II

Posted on 2014-10-06
7
Medium Priority
?
106 Views
Last Modified: 2014-10-07
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.
0
Comment
Question by:ceneiqe
  • 4
  • 3
7 Comments
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40363162
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
 

Author Comment

by:ceneiqe
ID: 40363733
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
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 2000 total points
ID: 40364062
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:ceneiqe
ID: 40366664
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
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40366730
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
 

Author Comment

by:ceneiqe
ID: 40367572
Thanks ! Yes it is working now.
Sorry i forgot to rename the file name back to the original name in the macro code.
0
 

Author Closing Comment

by:ceneiqe
ID: 40367576
expert was very fast, detailed and systematic.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question