Help please - delete cells/columns dependent on another cell value

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Can anyone help at all....if cell a1 (sheet1) =5 I want to delete cells g5 to k25 however if a1 (sheet1) =6 of want to delete cells h5 to k25. Cell a1 will change - if a1 =7 then I want to delete i5 to k25. Is there any way I can do this?

Thanks in advance
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
put this in the wroksheet change event for worksheet 1:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not (Intersect(Target, Range(Cells(1, 1), Cells(1, 1))) Is Nothing) Then
 nn = Target.Value
  If nn > 4 And nn < 8 Then
   Range(Cells(5, 2 + nn), Cells(25, 11)) = ""
  End If
End If


End Sub
 
Upvote 0
Sorry I was having problems getting this working - how do you mean by Worksheet Change Event? I didn't seem to work.
 
Upvote 0
To put code in the worksheet change event
From the excel window type ctrl F11, this will open the VBA project window
In the project explorer window on the left of the screen , right click the “sheet1” object and select “viewCode"
A new blank windows opens , in the left hand dropdown menu at the top, select “worksheet”
A bit of code appears in the blank window (ignore this)
In the right hand dropdown menu select “Change”
You should now have some code in the window that looks like this:
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

End Sub


Private Sub Worksheet_SelectionChange(ByVal Target As Range)


End Sub
Delete the last two lines and edit the worksheet change sub to look like my post above
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,110
Messages
6,128,894
Members
449,477
Latest member
panjongshing

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