Solved

How to delete a specific cell values in specific rows

Posted on 2016-09-13
10
57 Views
Last Modified: 2016-10-04
I have a specific row, "total respondents", that repeats over and over throughout this sheet. I need to be able to search each individual cell in each row and delete all cell values that are 5 or less (in some cases, there is a "<5", others there is a 1 or 2).

I would do a simple ctrl + f and replace but there could be situations where it would affect the mean and median in other sections of the worksheet.

I attached a screen shot so you can see what i'm looking at. It literally repeats like this throughout the sheet for about 4000 rows.

Can someone assist?
testing.PNG
0
Comment
Question by:nflynn85
  • 5
  • 4
10 Comments
 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 41796379
you can use condictional formatting putting <=5 and put color then filter by color and delete the values

or you can use the following VBA code.

make sure u run this on a copy.

Sub t()
Dim c As Range

For Each c In ActiveSheet.UsedRange
If c <= 5 Then
c.ClearContents
End If
Next c
End Sub

Open in new window

0
 
LVL 4

Expert Comment

by:AnthonyHamon
ID: 41796395
  1. On row 1 of the workbook, create a temporary header row and name the columns A, B, C, D, E etc.
  2. Mark all used cells in the workbook, go to the 'Data' tab and select 'Filter'
  3. Go to the top of the workbook
  4. Locate column that contains  the data labels (look likes column C from your attachment) and use the filter drop down on that column to show only the 'Total respondents' rows
  5. Use a simple find and replace which will only affect the visible cells
  6. Remove the filter
  7. Remove the temporary header
0
 

Author Comment

by:nflynn85
ID: 41796610
I'd really prefer to do this in/with VBA so I can run it again next year.

The VBA Code provided ended up wiping out values that I did not want wiped out. I want it focused only on the row for total respondents. Is that possible? Being able to replace it with —
would be really cool

Take a look at the updated picture with the code that I ran from above (testing vs testing2)
testing.PNG
testing2.PNG
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!

 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 41818631
@nflynn85

if you want to replace it with —  then use below code

Sub test()
Dim c As Range

For Each c In ActiveSheet.UsedRange
If c <= 5 Then
c.Value = "—"
End If
Next c
End Sub

Open in new window

0
 

Author Comment

by:nflynn85
ID: 41826544
Thanks for that update, but there was a prior issue that wasn't addressed. The values that are 5 or less need to be found on a case sensitive basis. I can't have 255 looking like 2-- or 374 looking like -7-

Does that make sense?
0
 
LVL 26

Assisted Solution

by:ProfessorJimJam
ProfessorJimJam earned 500 total points
ID: 41826636
@nflynn85

the code above does not replace 255 to  2--

please see attached example.

if you run the code, it will only replace those highlighted cells and not any other value.
Book1.xlsm
0
 

Author Comment

by:nflynn85
ID: 41827062
Thanks for that. I ran the code on my excel sheet and it worked fine. However, it placed dashes in all of the empty columns/rows in between tables

While I can see and read and understand what your code is doing, I don't know how to modify it so that the above code doesn't place the dashes in empty cells (see attached photo)
dashes.PNG
0
 
LVL 26

Accepted Solution

by:
ProfessorJimJam earned 500 total points
ID: 41827111
Then try this

Sub test()
Dim c As Range

For Each c In ActiveSheet.UsedRange
If c<>"" and c <= 5 Then
c.Value = "—"
End If
Next c
End Sub
0
 

Author Comment

by:nflynn85
ID: 41828003
Thank you sir! Works like a charm. Was able to modify it to take out additional values as well. Thanks for the assist
0
 
LVL 26

Expert Comment

by:ProfessorJimJam
ID: 41828112
You're welcome I'm glad I was able to help
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Modern/Metro styled message box and input box that directly can replace MsgBox() and InputBox()in Microsoft Access 2013 and later. Also included is a preconfigured error box to be used in error handling.
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 will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

679 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