Clear content of cells outside area of interest

yploo

New Member
Joined
Aug 2, 2021
Messages
19
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I am looking for a way to clear the content of all the cells outside my area of interest (designated by the orange oval):
Left.png
Right.png


Close up, it looks like this:
Zoomed.png


I would like to clear the content of ALL the cells that are not encircled, and including those coloured in orange.

How can this be done?

Thank you very much in advance!!!
 
Thanks for that overview. Even though much of it is well over my head, it is interesting reading and at least I now have some concept of what I was dealing with. :)
Again I would acknowledge @Snakehips who was able to understand what you were trying to achieve in Excel terms & express that in a way that I could understand.
I am pleased that we were able to assist and wish you good luck with your studies!
 
Upvote 0

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hello @Peter_SSs, I am back again with another issue ?

Previously, your code helped to clear all the cell content outside the 4 area of interests (AOI), the boundaries of which are defined by cells with the value of 255. The samples were placed next to each other, like this:
ssLC 4 dishes together.jpg


However, the experiment results had been undesirable, and I wanted to repeat the experiment with a different placement of the samples (ie. place them further apart from each other):
ssLC AL10 4 dishes apart.jpg


Somehow, the code that you wrote works for the first set of placement, where the 4 AOIs are close to each other, but not the second set.

The issue is always with this line of the code:
issue.jpg


Would you be able to help me again? I regret that I don't have sufficient knowledge in VBA to amend the code ?

The Excel workbook containing both the PNG and TIFF worksheets can be found here: https://wetransfer.com/downloads/3870a3991cd19d18ff2ed442708a61ce20220126091123/6ada36bc4f3671bd5f07346d7966e10f20220126091152/1700d1

All the 255 cells are coloured in green in the PNG sheet.

Thank you very much in advance!!!
 
Upvote 0
This project is pretty hazy to me and adjusting that code for the more unaligned circles was proving difficult so I have taken a new approach. Simpler anyway - providing it works. ?

Give this single procedure a try.

VBA Code:
Sub ClearOutside_v7()
  Dim wsTIFF As Worksheet
  Dim rA As Range, rBlank As Range, rErr As Range
  Dim c As Long, cols As Long
  
  Application.ScreenUpdating = False
  Set wsTIFF = Sheets("TIFF")
  wsTIFF.Columns(1).Insert
  With Sheets("PNG")
    .Columns(1).Insert
    cols = .Cells(1, Columns.Count).End(xlToLeft).Column
    .UsedRange.Replace What:=255, Replacement:="#N/A", LookAt:=xlWhole
    For c = 2 To cols
      For Each rA In .Columns(c).SpecialCells(2, 3).Areas
        Set rBlank = Nothing
        On Error Resume Next
        Set rBlank = rA.Offset(, -1).SpecialCells(4)
        On Error GoTo 0
        If Not rBlank Is Nothing Then
          rA.ClearContents
          wsTIFF.Range(rA.Address).ClearContents
        End If
      Next rA
    Next c
    For c = 2 To cols
      Set rErr = Nothing
      On Error Resume Next
      Set rErr = .Columns(c).SpecialCells(2, 16)
      On Error GoTo 0
      If Not rErr Is Nothing Then
        For Each rA In rErr.Areas
          rA.ClearContents
          wsTIFF.Range(rA.Address).ClearContents
        Next rA
      End If
    Next c
    .Columns(1).Delete
  End With
  wsTIFF.Columns(1).Delete
  Application.ScreenUpdating = True
  MsgBox "Done"
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top