Running macro

K

Kjellk

I would like to have this macro running not only when he workbook is opened
but also if it already is open:

Private Sub Workbook_Open()
Dim xR As Long
With Sheets("Databas")
For xR = 3 To .Cells(.Rows.Count, "F").End(xlUp).Row
If .Cells(xR, "F") > 4500 Then
.Rows(xR).EntireRow.Interior.Color = vbYellow
End If

If .Cells(xR, "K") > 1 Then
.Rows(xR).EntireRow.Interior.Color = vbRed
End If
If .Cells(xR, "M") > 1 Then
.Rows(xR).EntireRow.Interior.Color = 15773696
End If



Next
End With
End Sub
 
G

Gord Dibben

Stick this Sub in a general module.

Sub run_a_macro()
Dim xR As Long
With Sheets("Databas")
For xR = 3 To .Cells(.Rows.Count, "F").End(xlUp).Row
If .Cells(xR, "F") > 4500 Then
.Rows(xR).EntireRow.Interior.Color = vbYellow
End If
If .Cells(xR, "K") > 1 Then
.Rows(xR).EntireRow.Interior.Color = vbRed
End If
If .Cells(xR, "M") > 1 Then
.Rows(xR).EntireRow.Interior.Color = 15773696
End If
Next
End With
End Sub

Stick this in Thisworkbook module

Private Sub Workbook_Open()
run_a_macro
End Sub


Gord Dibben MS Excel MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top