macro to remove columns & adjust width

kts9365

Board Regular
Joined
Jul 8, 2004
Messages
58
Alright,

I need to delete a column and adjust columns widths based on a reference number in cell AA9. For instance, if cell AA9 equals 10 then I need to delete columns N:P, and set column widths for columns to 4.86. If cell AA9 = 9, then I need to delete columns M:P, and set column widths for columns to 5.57.

TIA
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Copy the this code into the VBA object of the worksheet :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

If Not Intersect(Target, Range("AA9")) Is Nothing Then
    Select Case Range("AA9").Value
        Case 10
            Columns("N:P").Delete
            Cells.ColumnWidth = 4.86
        Case 9
            Columns("M:P").Delete
            Cells.ColumnWidth = 5.57
    End Select
End If

End Sub


Success,
Erik
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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