Trying to clear certain columns if a name is present

zone709

Well-known Member
Joined
Mar 1, 2016
Messages
2,125
Office Version
  1. 365
Platform
  1. Windows
Hi trying to clear other columns other then if 523 9th ave is in H,L,P,T,X,AA,AD. As you can see i also need to keep the data from 3 columns before the name 523 9th ave. If anything other then 523 9th ave is present i need to clear it from the range only E to Ad.


Example:
Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAG
1SNOEmployee NameLocal\TradeIDMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAYTOTAL
24/27/20204/28/20204/29/20204/30/20205/1/20205/2/20205/3/2020
3STOTDTJOBSTOTDTJOBSTOTDTJOBSTOTDTJOBSTOTDTJOBSTOTJOBSTOTJOBSTOTDT
41JoeOffice18.001.002.00523 9th ave8.001.002.00
52MikeLaborer BK28.00523 9th ave8.000.000.00
63EdOffice38.002.003.00104 Ralph Ave8.002.003.00104 Ralph Ave8.001.001.00523 9th ave24.005.007.00
74RalphOffice48.00523 9th ave8.000.000.00
85LeeOffice78.001.001.50104 Ralph Ave8.001.001.00523 9th ave16.002.002.50
96TommyOffice118.001.001.00104 Ralph Ave8.00523 9th ave16.001.001.00
10Totals80.009.0012.50
11Overall Totals101.50
Data
Named Ranges
NameRefers ToCells
Print_Area=Data!$A$1:$AH$70AE4:AG10, AE11
Print_Titles=Data!$1:$3E2:AD2



Results:

Book1
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACAD
1SNOEmployee NameLocal\TradeIDMONDAYTUESDAYWEDNESDAYTHURSDAYFRIDAYSATURDAYSUNDAY
24/27/20204/28/20204/29/20204/30/20205/1/20205/2/20205/3/2020
3STOTDTJOBSTOTDTJOBSTOTDTJOBSTOTDTJOBSTOTDTJOBSTOTJOBSTOTJOB
41JoeOffice18.001.002.00523 9th ave
52MikeLaborer BK28.00523 9th ave
63EdOffice38.001.001.00523 9th ave
74RalphOffice48.00523 9th ave
85LeeOffice78.001.001.00523 9th ave
96TommyOffice118.00523 9th ave
Data
Named Ranges
NameRefers ToCells
Print_Titles=Data!$1:$3E2:AD2
 
Hi thanks for the reply. So this works for the address i put above which is great, but i probably would like to change the name in the code sometimes. When i do that it doesn't work. Like say i put in 104 Ralph Ave. It then wont work. Is it because its of the .Value. Do I need to change something if I change the name sometimes?
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
You're welcome & thanks for the feedback.
 
Upvote 0
Hi just thought i reach out one more time to see if i can do this since i realize when running this maybe it can be even easier. Sometimes when i use this i have to change the job name in the code to have make this work differently. Anyway the code can pick up the name on the activesheet instead of me changing it everytime. So lets say on the sheet ill type in the name in the cell AJ3 every time then run the code. Meaning use cell AJ3 to identify the name to use in the code.
 
Upvote 0
Just replace the text value, with a cell reference.
 
Upvote 0
HI i changed code. It doesn't break which is good ,but doesn't work. I put n5 to test it. I have name in the n5 cell. I think i am missing something in the code though.

VBA Code:
Sub zone()
   Dim Cl As Range, Rng1 As Range, Rng2 As Range
   
   With Range("A4", Range("A" & Rows.Count).End(xlUp))
      Set Rng1 = Intersect(.EntireRow, Range("H:H,L:L,P:P,T:T,X:X"))
      Set Rng2 = Intersect(.EntireRow, Range("AA:AA,AD:AD"))
   End With
   For Each Cl In Rng1
      If Cl.Cells <> "" And LCase(Cl.Cells) <> "n5" Then
         Cl.Offset(, -3).Resize(, 4).Cells = ""
      End If
   Next Cl
   For Each Cl In Rng2
      If Cl.Cells <> "" And LCase(Cl.Cells) <> "n5" Then
         Cl.Offset(, -2).Resize(, 3).Cells = ""
      End If
   Next Cl
End Sub
 
Upvote 0
You need to do it like
VBA Code:
LCase(Cl.Cells) <> range("n5").value
 
Upvote 0

Forum statistics

Threads
1,223,275
Messages
6,171,121
Members
452,381
Latest member
Nova88

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