+ Reply to Thread
Results 1 to 4 of 4

Simple macro (ClearContent) freezes Excel

  1. #1
    Registered User
    Join Date
    03-08-2006
    Posts
    3

    Simple macro (ClearContent) freezes Excel

    Hi,

    I have this very simple macro:

    Sheets("adjustment").Select
    Range("B9:J25").Select
    Application.CutCopyMode = False
    Selection.ClearContents

    Before I run this macro the following things are happening:
    - datas are pasted into a different sheet
    - these datas are copied into B9:J25

    When the destination area contains data then this macro freezes Excel. If there are no data then it runs "smoothly" (It also runs when I put data manually into those cells)
    What should I do to make this macro work?

    Thanks,

    Laszlo

  2. #2
    Peter T
    Guest

    Re: Simple macro (ClearContent) freezes Excel

    Is your code in a Worksheet module, eg activated by a Worksheet ActiveX
    control. If so and you are using Excel97 change the TakeFocusOnClick
    property of the CommandButton to False. In all versions, if
    Sheets("adjustment") is not the sheet containing the commandbutton this line
    will fail

    Range("B9:J25").Select

    unless you change it to
    Sheets("adjustment").Range("B9:J25").Select

    But if your macro is in a normal module not sure what the problem is, try

    Sheets("Sheet2").Range("B9:J25").ClearContents

    Regards,
    Peter T

    "bokodilaszlo" <[email protected]>
    wrote in message
    news:[email protected]...
    >
    > Hi,
    >
    > I have this very simple macro:
    >
    > Sheets("adjustment").Select
    > Range("B9:J25").Select
    > Application.CutCopyMode = False
    > Selection.ClearContents
    >
    > Before I run this macro the following things are happening:
    > - datas are pasted into a different sheet
    > - these datas are copied into B9:J25
    >
    > When the destination area contains data then this macro freezes Excel.
    > If there are no data then it runs "smoothly" (It also runs when I
    > put data manually into those cells)
    > What should I do to make this macro work?
    >
    > Thanks,
    >
    > Laszlo
    >
    >
    > --
    > bokodilaszlo
    > ------------------------------------------------------------------------
    > bokodilaszlo's Profile:

    http://www.excelforum.com/member.php...o&userid=32250
    > View this thread: http://www.excelforum.com/showthread...hreadid=520012
    >




  3. #3
    Registered User
    Join Date
    03-08-2006
    Posts
    3
    Hi Peter,

    Thanks for your help, I tried your suggestions but they didn't work.
    I figured out that my macro is working until this line:

    Selection.ClearContents

    So I think the problem is in there somewhere. The funny thing is that I wrote the same macro for different cells in different sheets and it works there....

  4. #4
    Registered User
    Join Date
    03-08-2006
    Posts
    3
    I did some searching and I found that ClearContents doesn't play
    nicely with merged cells. And I had merged cells in that area (B9:J25)!
    So I modified that sheet to contain only single cells. And now the macro works fine

+ Reply to Thread

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