Home |
Search |
Today's Posts |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I haven't been through your code with a fine tooth comb but is the sheet you
need for that part of the code the active sheet? Is j a valid number for the row? However, do you really need activesheet? What I mean by this, does it affect your code if it is called from a different active sheet and you need the active sheet reference or does the code still act on the same sheets irrespective of where it is callled from? If the latter, then leave the code as you had it before with the sheet names. If you need to know the active sheet, then I recall that there are some issues in calling subs outside of the sheet code area. I had forgotten this until you raised your problem. I think that the workaround is to call the macro and pass the active sheet name as a parameter. You do this as follows:- Private Sub CommandButton1_Click() Dim strTemp As String strTemp = ActiveSheet.Name Call MyCommandButton(strTemp) End Sub The called sub is then like this example:- Sub MyCommandButton(myActSheet As String) j = 30 'Dummy value for testing With Sheets(myActSheet) Range("F6").Value = _ Application.WorksheetFunction.Sum _ (.Range(.Cells(2, 2), .Cells(j, 2))) End With End Sub Regards, OssieMac |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
UNIQ EXPEREINCE: PROCEDURE WORKS FINE USING F8 BUT GET ERROR WHEN COMMAND BUTTON IS CLICKED | Excel Programming | |||
Command button code | Excel Programming | |||
Excel macro works with keyboard shortcut, but not command button. Please Help. | Excel Programming | |||
Opening an Outlook public folder from Excel using a command button... | Excel Programming | |||
how do I set up a command button that works with a combo box | Excel Discussion (Misc queries) |