PC Review


Reply
Thread Tools Rate Thread

Code with formula interfering in worksheet change event

 
 
Arnold
Guest
Posts: n/a
 
      26th Jan 2007
Hello,
When this code is in the worksheet change event, it restricts the
function of other code in worksheet change. Why? Is it about the
placement of the Exit Sub? All this code does is carries formulas in
columns 3 and 10 down to new rows when inserted manually.

If Intersect(Target, Me.Range("A:A")) Is Nothing Then Exit Sub
On Error Goto CleanUp:
With Target
If .Value <> "" Then
Application.EnableEvents = False
.Offset(0, 3).FormulaR1C1 = "=RC[-1]=R2C3"
.Offset(0, 10).FormulaR1C1 = "=RC[-1]=R2C10"
.Offset(0, 2).FormulaR1C1 = "=if(rc[-2]<>"""",rc[-1],"""")"
.Offset(0, 9).FormulaR1C1 =
"=if(rc[-8]<>0,if(rc[-7]<>rc[-8],rc[-9]&"",
""&left(rc[-7],2),rc[-9]&"", ""&left(rc[-8],1)),"""")"
End If
End With
CleanUp:
Application.EnableEvents = True

Also, could you help me with syntax for another vb formula that
essentially is this:
=OFFSET(Column10sHeading,0,246)
which just sets the last column equal to column 10.

Thanks greatly,
Eric

 
Reply With Quote
 
 
 
 
Joerg
Guest
Posts: n/a
 
      26th Jan 2007
Which other code?
And what do you mean by "restrict"?


"Arnold" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
> When this code is in the worksheet change event, it restricts the
> function of other code in worksheet change. Why? Is it about the
> placement of the Exit Sub? All this code does is carries formulas in
> columns 3 and 10 down to new rows when inserted manually.
>
> If Intersect(Target, Me.Range("A:A")) Is Nothing Then Exit Sub
> On Error Goto CleanUp:
> With Target
> If .Value <> "" Then
> Application.EnableEvents = False
> .Offset(0, 3).FormulaR1C1 = "=RC[-1]=R2C3"
> .Offset(0, 10).FormulaR1C1 = "=RC[-1]=R2C10"
> .Offset(0, 2).FormulaR1C1 = "=if(rc[-2]<>"""",rc[-1],"""")"
> .Offset(0, 9).FormulaR1C1 =
> "=if(rc[-8]<>0,if(rc[-7]<>rc[-8],rc[-9]&"",
> ""&left(rc[-7],2),rc[-9]&"", ""&left(rc[-8],1)),"""")"
> End If
> End With
> CleanUp:
> Application.EnableEvents = True
>
> Also, could you help me with syntax for another vb formula that
> essentially is this:
> =OFFSET(Column10sHeading,0,246)
> which just sets the last column equal to column 10.
>
> Thanks greatly,
> Eric
>



 
Reply With Quote
 
Arnold
Guest
Posts: n/a
 
      26th Jan 2007
Here's the other code. By restrict, I meant that the code below
doesn't work when the above code is in the sheet event. The code below
puts the value of cells in the last column (range is AbbNames) equal to
the cells in column 10 (range Abbreviated), and then updates any
changed values on another sheet, Schedules.

On Error GoTo errHandler

If Target.Count > 1 Then Exit Sub

On Error Resume Next
Set rng = Target.Dependents
On Error GoTo 0
If Not rng Is Nothing Then
Set rng1 = Union(rng, Target)
Else
Set rng1 = Target
End If

On Error GoTo errHandler

If Not Application.Intersect(rng1, _
Application.Range("Abbreviated")) Is Nothing Then
strOld = Target.EntireRow.Range("IV1").Value
strNew = Target.EntireRow.Range("J1").Value

Application.EnableEvents = False
Application.ScreenUpdating = False

Application.Range("AbbNames").Value = _
Application.Range("Abbreviated").Value
End If


Set wsData = Worksheets("Schedules")

On Error GoTo errHandler

Set myRange = wsData.Range("Students")
For Each mycell In myRange
If mycell.Value = "" Then
Else
If strOld <> strNew And strOld <> "" Then

Application.EnableEvents = False
Application.ScreenUpdating = False

wsData.Range("Students").Replace What:=strOld, _
Replacement:=strNew, LookAt:=xlPart, _
SearchOrder:=xlByRows

End If
End If
Next

Application.Range("AbbNames").Value = _
Application.Range("Abbreviated").Value

errHandler:

Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic

If Err.Number <> 0 Then _
MsgBox "Error occured " & Err.Number & vbNewLine & _
Err.Description

exitHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic

Exit Sub

End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Microsoft Excel Programming 6 3rd Oct 2008 09:45 PM
Worksheet Change event code, but retain Undo? =?Utf-8?B?bWFyaw==?= Microsoft Excel Programming 11 13th Sep 2007 08:40 PM
Worksheet Change event code moved to Worksheet Calculate event... and it's not working KimberlyC Microsoft Excel Programming 5 23rd Jun 2005 10:35 PM
Enable/Disable Worksheet Change Event code Stuart Microsoft Excel Programming 2 3rd Nov 2003 07:22 PM
Copy Sheets minus Worksheet Change Event code & Macro Buttons Bob Microsoft Excel Programming 0 8th Oct 2003 01:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:02 PM.