ranges with variables or protect?

MRA

New Member
Joined
Jun 27, 2008
Messages
36
Hey guys, so
I'm trying to set up some code such that cells are autoupdated based on changes in some other cells. I also want any further changes to wipe out the previous update.
In other words, I want values I place in a particular cell to be shifted to the left based on the value in another cell. But if I change the value later, I want the first value that the macro entered to be wiped. I have the data the macro uses in that row as well however, so that can't be wiped.
It's kinda odd to explain I know, but hopefully that makes sense.

My first thought was to define a variable using the target row and Range, but I can't quite figure out how to do that...
My next thought, displayed below, was to protect the cells I wanted and then unprotect them after I wiped the row.


Here's what I have so far,

Code:
Private Sub worksheet_change(ByVal target As range)
If Not Intersect(target, range("c1:c1000")) Is Nothing Then
Dim tgt As Long

tgt = target.Row
Worksheets("sheet1").Protect Contents: ["a1:c1000"] = True
ActiveSheet.Row(tgt).Delete
Worksheets("sheet1").Protect Contents: ["a1:c1000"] = False

ActiveSheet.Cells(tgt, (Cells(tgt, 2) + 3)).Value = (Cells(tgt, 3))
End If
End Sub

seems like I have a syntax error in the protect lines as well.
If anyone can fix this, or knows a better way, any help would be greatly appreciated
Thanks in advance,
Mike
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,214,951
Messages
6,122,449
Members
449,083
Latest member
Ava19

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