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
Solved

How to delete a specific cell values in specific rows

Posted on 2016-09-13
10
54 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

792 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