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

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

WinteE

Well-known Member
Joined
Apr 8, 2007
Messages
605
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,195,695
Messages
6,011,173
Members
441,591
Latest member
elmogm

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
Top