delete calculated columns

lefty38

Board Regular
Joined
Oct 27, 2005
Messages
85
I have a borrowed VBA Code that will delete columns that = NR ( =IF((K1=0),"NR",(K2/K1)) )
problem is when the cells shift after deleting ==> the code seems to skip over other NR fields


I have attached the code and a small sample of the excel sheet
column range can be from H3 to many columns
calculations are turned off until this practical script runs (to save time)

thank you for any help

Code:
Sub deleteNRcolumns()
Dim Rng As Range, cell As Range
'turn on Autocalc so the NR comlumns can be deleted
    Application.ScreenUpdating = True
       With Application
        .Calculation = xlAutomatic
        .MaxChange = 0.001

    Set Rng = Range("H3:CA3")
  
        For Each cell In Rng
            Select Case cell.Value
            Case Is = "NR"
                cell.EntireColumn.Delete
        End Select
    Next cell
    
      End With


[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]4
[/TD]
[TD][/TD]
[TD]4
[/TD]
[TD]1
[/TD]
[TD][/TD]
[TD]4
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]4
[/TD]
[TD][/TD]
[TD]4
[/TD]
[TD]1
[/TD]
[TD][/TD]
[TD]4
[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]100%
[/TD]
[TD]NR
[/TD]
[TD]100%
[/TD]
[TD]100%
[/TD]
[TD]NR
[/TD]
[TD]100%
[/TD]
[TD]NR
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Country
[/TD]
[TD]State
[/TD]
[TD]City
[/TD]
[TD]Mgr
[/TD]
[TD]Emp
[/TD]
[TD]ID
[/TD]
[TD]Comp
[/TD]
[TD]crs1
[/TD]
[TD]crs2
[/TD]
[TD]crs3
[/TD]
[TD]crs4
[/TD]
[TD]crs5
[/TD]
[TD]crs6
[/TD]
[TD]crs7
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]fred
[/TD]
[TD]01
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]wilma
[/TD]
[TD]02
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]barny
[/TD]
[TD]03
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]bam
[/TD]
[TD]04
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
any help on message #9 ?

Is there a way to turn the ROW H3:CA3 (or how many columns wide from H3)
Code:
[H3:CA3] = [IF(H3:CA3="NR","",H3:CA3)]
to a hard coded "NR" (or percentage) ==> then delete the "NR" column(s)
then re-insert the
"=IF((H1=0),"NR",(H2/H1))" back into H3 and the remaining row 3 columns?

or another solution?
 
Upvote 0

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.

Forum statistics

Threads
1,223,911
Messages
6,175,324
Members
452,635
Latest member
laura12345

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