kaisersose
Registered User.
- Local time
- Today, 04:59
- Joined
- Sep 25, 2008
- Messages
- 13
Oops: Should be Want to run macro when file is saved....
I want to run this macro when the file is saved ( at the moment I have it so that the macro runs when the file is closed)
Have only started using macros recently so still learnign this stuff, can anybody tell me how I would go about getting this macro to run everytime the file is saved? Its basically copying data from one sheet to another. (I've tried Private Sub Workbook_Save() , but it doesnt run the macro)
Any help would be appreciated
Private Sub Workbook_BeforeClose(Cancel As Boolean)
End Sub
Sub Auto_Close()
Worksheets("Data").Activate
'Clear Report Sheet
Worksheets("Daily").Range("a5:j13").Value = ""
'Declare Row and column variables and initialize
Dim ReportRow As Integer ' Row counter for Report Sheet
ReportRow = 5 ' Set to 2 to allow for header row
Dim Dat As Date
Dim Row As Integer
Dim Col As Integer
Row = 4
Col = 2
Dat = Worksheets("Data").Range("k1")
For Each cell In Range("a5:a5000")
If Not IsError(cell.Value) Then
Row = Row + 1
With cell.Interior
Select Case cell.Value
Case Is = Dat
For Col = 1 To 10
Worksheets("Daily").Cells(ReportRow, Col) = Worksheets("Data").Cells(Row, Col)
Next Col
ReportRow = ReportRow + 1
Case Else
End Select
End With
Else
cell.Interior.ColorIndex = xlAutomatic
MsgBox ("The Item " + Data + " Is not Listed")
End If
Next cell
Worksheets("Daily").Activate
MsgBox ".... REPORT READY....." + Chr$(13) + "Please check that all rows have " + Chr$(13) + "valid data before Printing"
End Sub
I want to run this macro when the file is saved ( at the moment I have it so that the macro runs when the file is closed)
Have only started using macros recently so still learnign this stuff, can anybody tell me how I would go about getting this macro to run everytime the file is saved? Its basically copying data from one sheet to another. (I've tried Private Sub Workbook_Save() , but it doesnt run the macro)
Any help would be appreciated
Private Sub Workbook_BeforeClose(Cancel As Boolean)
End Sub
Sub Auto_Close()
Worksheets("Data").Activate
'Clear Report Sheet
Worksheets("Daily").Range("a5:j13").Value = ""
'Declare Row and column variables and initialize
Dim ReportRow As Integer ' Row counter for Report Sheet
ReportRow = 5 ' Set to 2 to allow for header row
Dim Dat As Date
Dim Row As Integer
Dim Col As Integer
Row = 4
Col = 2
Dat = Worksheets("Data").Range("k1")
For Each cell In Range("a5:a5000")
If Not IsError(cell.Value) Then
Row = Row + 1
With cell.Interior
Select Case cell.Value
Case Is = Dat
For Col = 1 To 10
Worksheets("Daily").Cells(ReportRow, Col) = Worksheets("Data").Cells(Row, Col)
Next Col
ReportRow = ReportRow + 1
Case Else
End Select
End With
Else
cell.Interior.ColorIndex = xlAutomatic
MsgBox ("The Item " + Data + " Is not Listed")
End If
Next cell
Worksheets("Daily").Activate
MsgBox ".... REPORT READY....." + Chr$(13) + "Please check that all rows have " + Chr$(13) + "valid data before Printing"
End Sub
Last edited: