Help with vba code placement please

Get_Involved

Active Member
Joined
Jan 26, 2007
Messages
383
I have been trying to get this to work in cell "Q4" all morning.
I have put it every where in thisworkbook, Legend, and in a new module.
Cant get it to work in cell "Q4" of the Legend.
This is the formula I am useing.

Code:
 Private Sub Workbook_Open()
Sheets("Sheet1").Range("Q4").Value = CInt(Format(Date, "ww", 1))
End Sub
Can someone help with advise please?
Thanks in advance
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
It goes in ThisWorkbook, and you have to save as a macro-enabled file, and then enable macros.
 
Upvote 0
shg:
I already have already done that several times, and this is the "Compile error" I receive. Ambiguous name detected Workbook_Open.
So I know I am doing something wrong.
I even created a new micro enabled file and enabled macros.
Thanks for the quick reply
 
Upvote 0
Ambiguous name detected Workbook_Open
That usually implies that you have two procedures named "Workbook_Open" in a single module, which is not allowed.
You cannot have multiple procedures by the same name in a module.
If they are performing two different tasks, then you will need to combine them in a single "Workbook_Open" event procedure.
 
Upvote 0
Joe4:
Thanks for the reply.
I figured that is what I am doing, I have done that also, that means I am not putting it in proper way.
This is how it starts
Code:
 Private Sub Workbook_Open()
 Dim Ans As String
 Ans = MsgBox("Update Invoice Number (???)", vbYesNo + vbInformation)
 If Ans = vbYes
Then and there is 18 rows of code down.
all of that is working.
Q4 is my problem, with placement of the weeknum.
hope I explained it clear enough
 
Last edited by a moderator:
Upvote 0
You would just have two "blocks" of code within your Workbook_Open event procedure, i.e.
Code:
 Private Sub Workbook_Open()
 
[COLOR=#0000ff] '  Block 1[/COLOR]
[COLOR=#0000ff]    Dim Ans As String[/COLOR]
[COLOR=#0000ff]    Ans = MsgBox("Update Invoice Number (???)", vbYesNo + vbInformation)[/COLOR]
[COLOR=#0000ff]    If Ans = vbYes Then[/COLOR]
[COLOR=#0000ff]        ...[/COLOR]
[COLOR=#0000ff]    End If[/COLOR]
    
[COLOR=#ff0000]'   Block 2[/COLOR]
[COLOR=#ff0000]    Sheets("Sheet1").Range("Q4").Value = CInt(Format(Date, "ww", 1))[/COLOR]
[COLOR=#ff0000]      [/COLOR]
 End Sub
 
Upvote 0

Forum statistics

Threads
1,214,830
Messages
6,121,839
Members
449,051
Latest member
excelquestion515

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