Solved

Macro to automatically delete row with data with specfic criteria II

Posted on 2014-10-06
7
99 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 500 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
Technology Partners: 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!

 

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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Excel Web Add-in Where is Visual Basic used 9 76
Populate MS Word Document table with information from excel 15 56
EXCEL String-handling question ... 7 51
sort time order 10 45
Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

732 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