Run a maco when worksheet opens

jwgreen

Board Regular
Joined
May 3, 2008
Messages
156
Hi All,

Im sure this one is an easy one but I cant seem to figure it out. Ive seached but found nothing that helps. What I need is to run a marco when I open the worksheet that it is in. Heres what I have.
Code:
Sub Cell_Select()
ActiveWorkbook.Sheets("MAR").Activate
    Range("B7").Select
    Do
    If IsEmpty(ActiveCell) = False Then
        ActiveCell.Offset(1, 0).Select
    End If
    Loop Until IsEmpty(ActiveCell) = True
End Sub

Any help is appreciated. Thanks in advance!
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
this must be add to the Thisworkbook model. in the VBA editor right click thisworkbook and click View code and past it in.

Code:
Sub workbook_open()
ActiveWorkbook.Sheets("MAR").Activate
    Range("B7").Select
    Do
    If IsEmpty(ActiveCell) = False Then
        ActiveCell.Offset(1, 0).Select
    End If
    Loop Until IsEmpty(ActiveCell) = True
End Sub
 
Upvote 0
If all you're trying to do is get to the first empty cell in column B, then why not just use:

Sheets("MAR").Cells(Rows.Count."B").End(xlup).Offset(1)

I'll be a whole lot faster than selecting and looping like that.

In addition, if you're trying to do this on all sheets (as it seems likely you have 12 monthly sheets), I'd replace "Sheets("MAR")" with "ActiveSheet" and put the code in the WorkBook_SheetActivate event.

HTH,
 
Upvote 0
Smitty,

I messed around with the code but could not get it to work. This is what I have placed in the ThisWorkbook Module.
Code:
Sub WorkBook_SheetActivate()
ActiveSheet.Cells(Rows.Count."B").End(xlup).Offset(1)
End Sub

I get the error "Compile error: Expected: identifier or bracketed expression"

Thanks for the help.
 
Upvote 0
ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Offset(1).Select

You have a period before "B". ;)
 
Upvote 0
Smitty,

Ahh I see it now.... but Now Im getting a "Procedure declaration does not match description of event or procedure having same name" Error.
 
Upvote 0
Seiya,

Thanks for the help but once again another error now

"Object doesn't support this property or method (Error 438)"

Heres the code.

Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Offset (1)
End Sub
 
Upvote 0
Is this what you are trying to do ?
Rich (BB code):
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
Sh.Cells(Rows.Count, "B").End(xlUp).Offset(1).Activate
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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