Results 1 to 6 of 6

Excel 2007 : Macro stopped working

Threaded View

  1. #1
    Registered User
    Join Date
    10-13-2010
    Location
    Wichita
    MS-Off Ver
    Excel 2007
    Posts
    4

    Macro stopped working

    Usually I can solve most programming issues by surfing the web, but this one is different.
    About 2 months ago my work moved from Office 2003 to Office 2007. My macros worked for a little while but then some stopped. Basically any macro that executes on a selection in a worksheet will now only partially work on the first cell. For instance:

    Sub WriteCellFormula()
        Dim temp As String
        For k = 0 To Selection.Rows.Count - 1
            For j = 0 To Selection.Columns.Count - 1
                If ActiveCell.Offset(k, j) <> "" Then
                    temp = "=substitute(CONCATENATE(SUBSTITUTE(CELL(""address"",ABCXYZ),""$"",""""),"" = "",SUBSTITUTE(cellformula(LEFT(CELL(""address"",ABCXYZ),LEN(CELL(""address"",ABCXYZ)))),""="","""")),""$"","""")"
                    temp = Application.WorksheetFunction.Substitute(temp, "ABCXYZ", ActiveCell.Offset(k, j))
                    ActiveCell.Offset(k, j).Formula = temp
                    ActiveCell.Offset(k, j).HorizontalAlignment = xlLeft
                End If
            Next j
        Next k
    End Sub
    This is a macro I have used without hickup for 2+ years, until recently.

    Basically this is a complicated way of writing a cell formula in a cell. It was made more complicated because I had to trick it into updating when the referenced cell updated. If I enter "A4" in cell B5 and highlight B5 and run this macro, it will write a cell formula to B5 which will return the cell formula of A4. Fine and good. When the formula in A4 changes, B5 is automatically updated. If you highlight a range (always had to drag to the left and down to work properly), it would do the same for all cells in the range. Now it only does the first cell. The funny thing is it never executes past the line:

    ActiveCell.Offset(k, j).Formula = temp
    I can put a msgbox after this line and it will never come up, before the line it will.

    What gives?

    BTW: Function cellformula:
    Function CellFormula(loc)
         CellFormula = ActiveSheet.Range(loc).Formula
    End Function
    Last edited by davesexcel; 10-13-2010 at 06:51 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1