Solved

Macro to automatically delete row with data with specfic criteria II

Posted on 2014-10-06
7
86 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 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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now