?
Solved

Macro to automatically delete row with data with specfic criteria II

Posted on 2014-10-06
7
Medium Priority
?
102 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

762 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