can't get a macro to work when i open a sheet

still learning

Well-known Member
Joined
Jan 15, 2010
Messages
821
Office Version
  1. 365
Platform
  1. Windows
Hi,
I open a workbook and have a few worksheets
I can’t get this to work when I open a worksheet
It worked last month
I tried the following:
I used F5 to send the cursor to the range name “August” and it worked.
I used F8 starting on >>>> Private Sub…..and it worked
I ran this before opening the sheet ---and it didn’t work
VBA Code:
Sub enableevents()
Application.enableevents = True
End Sub
VBA Code:
Private Sub Worksheet_activate()
months
End Sub
Sub months()
On Error Resume Next
Application.Goto Reference:=Range(Format(Date, "mmmm")), Scroll:=True
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveWindow.FreezePanes = True
Dim C As Range
Set C = Range("H1:H450").Find(Date)
If Not C Is Nothing Then C.Select
If ActiceCell.Row < 12 Then ActiveWindow.ScrollRow = ActiveCell.Row - 12
Selection.End(xlToLeft).Select
End Sub
When I open the sheet, the cursor is where it was when I save and close


Mike
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Try changing the name of the enableevents sub to something else then run it
 
Upvote 0
I don't where you expect the cursor to end. I don't have the data you have so My cursor ended up in column A
 
Upvote 0
Hi MARK858,
I tried putting >>>Application.Enableevents = True <<< before calling for the macro "months".
the "months" macro did not run.

Hi Jeff,
H1:H450 has months and dates>>>H1 = January...H2 = 1/1/2024... H3 = 1/2/2024
each cell that has a month name also has a range name.
H1 which has January in it has a range name as January. This is true for the whole year
I want the cursor to go to the range that is the current month. It worked for all the previous months
Then do "stuff"
It stopped working when we hit August 1
What it does now is nothing. on opening, the cursor is where it was when i saved and closed the program
It works fine for F8
I put the cursor on "Private Sub Worksheet_activate()" and run thru the macro using F8. it works perfect
It worked fine for the other months.
I've not change anything...except for adding the >>>Application.Enableevents = True <<< a couple of hours ago

mike
 
Upvote 0
Comment out the On Error Resume Next line so you can see what actually happens (also what error were you getting to have it there in the first place)
 
Upvote 0
I took out the On Error Resume Next line and got no error message. I don't remember why I had it in.
I put a icon on the ribbon to run "months".
I changed

Application.Goto Reference:=Range(Format(Date, "mmmm")), Scroll:=True
to
Application.Goto Reference:=Range("August"), Scroll:=True
and the macro ran perfect.
I didn't have this problem in previous months.
Here is the macro with the revisions that ran perfect with the ribbon icon
VBA Code:
Sub months()
        '   On Error Resume Next
Application.Goto Reference:=Range("August")), Scroll:=True
       '   Application.Goto Reference:=Range(Format(Date, "mmmm")), Scroll:=True
ActiveCell.Offset(1, 0).Range("A1").Select
ActiveWindow.FreezePanes = True
Dim C As Range
Set C = Range("H1:H450").Find(Date)
If Not C Is Nothing Then C.Select
If ActiceCell.Row < 12 Then ActiveWindow.ScrollRow = ActiveCell.Row - 12
Selection.End(xlToLeft).Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,884
Messages
6,175,175
Members
452,615
Latest member
bogeys2birdies

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