ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Activate Event Before Saving (https://www.excelbanter.com/excel-programming/389170-activate-event-before-saving.html)

J-D[_2_]

Activate Event Before Saving
 
I want this event to activate before saving the file. Pls, can
anbody show me what is wrong or missing?

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

For myloop = 1 To 14
ActiveSheet.Cells(Target.Row, myloop).Interior.ColorIndex = icolor
Next
End If

End Sub

I cannot figure this out... Pls help.


Dave Peterson

Activate Event Before Saving
 
You have an active thread elsewhere.

J-D wrote:

I want this event to activate before saving the file. Pls, can
anbody show me what is wrong or missing?

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

For myloop = 1 To 14
ActiveSheet.Cells(Target.Row, myloop).Interior.ColorIndex = icolor
Next
End If

End Sub

I cannot figure this out... Pls help.


--

Dave Peterson

joel

Activate Event Before Saving
 
Target is not defined. I usually see Target as one of the parameters passed
in a worksheet_chage macro. This is a Before_Save which doesn't accept a
passed range variable.

"J-D" wrote:

I want this event to activate before saving the file. Pls, can
anbody show me what is wrong or missing?

Option Explicit
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)

Dim icolor As Integer

If Not Intersect(Target, Range("A6:n2000")) Is Nothing Then
Select Case Target
Case 15
icolor = 4
Case -15
icolor = 46
Case 100
icolor = 6
Case -100
icolor = 3
Case Else
'Whatever
End Select

For myloop = 1 To 14
ActiveSheet.Cells(Target.Row, myloop).Interior.ColorIndex = icolor
Next
End If

End Sub

I cannot figure this out... Pls help.



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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com