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


4
4
1
4
4
4
1
4
100%
NR
100%
100%
NR
100%
NR
Country
State
City
Mgr
Emp
ID
Comp
crs1
crs2
crs3
crs4
crs5
crs6
crs7
fred
01
wilma
02
barny
03
bam
04

<tbody>
</tbody>
 
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

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

Forum statistics

Threads
1,216,098
Messages
6,128,812
Members
449,468
Latest member
AGreen17

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