Running and Macros & Active Worksheets

mhp620

New Member
Joined
Jan 6, 2010
Messages
25
Hi... I'm pretty much a VBA hacker and not formally trained. So apologies if this is a rudimentary question...

I have a macro that runs fine in the workbook in which it is saved. But when I open a new workbook and try to run this macro, an "update value" dialogue keeps opening up and I have to crash Excel to break out of it.

Is there a way to run this macro without having to first move it the new workbook?

Thanks in advance, mike
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Mike,

Have you tried saving it as an addin-in? That way it should be accessible to all workbooks?

AMAS
 
Upvote 0
Tried that, as well as putting it in the Personal file... I get the same error as running it from another workbook.... a Windows "Update Value" dialog wanting a choice of a file.

If I move the macro into the workbook, then it runs fine. But this is not possible operationally.

The first few line of the macro are:

Sub MY_Summary1()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>
<o:p> </o:p>
Dim iCount As Integer<o:p></o:p>
<o:p> </o:p>
For iCount = 2 To ActiveWorkbook.Sheets.Count<o:p></o:p>
Range("A15").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "Asset Class"<o:p></o:p>
Range("B15").Select<o:p></o:p>
ActiveCell.FormulaR1C1 = "Fund Name"<o:p></o:p>
Sheet1.Cells((14 + iCount), 2).Value = "='" & ActiveWorkbook.Sheets(iCount).Name & "'!E1"<o:p></o:p>
.<o:p></o:p>
.<o:p></o:p>
.<o:p></o:p>
The dialog opens on the line starting "Sheet1.Cells((14 + iCount), 2).Value ..."

Any other advice or ideas?

Thanks. Mike
 
Upvote 0
Hi Mike,

I think I have spotted the problem. Instead of Sheet1.Cells use the sheets object with a name qualifier. Therefore Sheets(1).Cells or Sheets("Sheet1").Cells.

I have modified this bit of code and seems to work from my end:

Code:
Sub MY_Summary2()
Dim iCount As Integer
    For iCount = 2 To ActiveWorkbook.Sheets.Count
        Range("A15:B15") = [{"Asset Class", "Fund Name"}]
        Sheets("Sheet1").Cells((14 + iCount), 2).Value = "=" & ActiveWorkbook.Sheets(iCount).Name & "!E1"
    Next iCount
End Sub

AMAS
 
Upvote 0

Forum statistics

Threads
1,224,587
Messages
6,179,738
Members
452,940
Latest member
Lawrenceiow

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