+ Reply to Thread
Results 1 to 14 of 14

VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

  1. #1
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Hi Guys,
    Will need guru to enlighten me. I do not have any merged cell where excel highlighted the specific cell which are merged. When i check it, it is not.

    Being google around, most of the user faced problem which cell is merged, but mine is not

    Attached with my workbook. I facing problem only when i click on sheet2's command button which running same module for the command button on sheet1.
    Last edited by cychua; 01-24-2013 at 05:33 AM. Reason: attached file with my company logo

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    You do not have a code on the attached and not sure what are trying to do, but if you wish to remove merged cells, run this code.

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Sorry my bad. This file should be the correct 1. Due to my excel is structured with formula. I worry that if i unmerged some of the cell would cause error on formula as well.
    Attached Files Attached Files
    Last edited by cychua; 01-24-2013 at 05:39 AM.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Please do not reply with quote. It has not purpose, but clutters the space.
    You have few codes on the attached. I suspect this code "Sub NextScreening()" you are looking at. Right! I will have a look and get back to ASAP

  5. #5
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    I am a noob for Excel. My current workbook is contributed from Excelforum the most and 30%-40% is from google.

    I create a command button with Module1's macro on sheet1. And i wish to have the same command button on sheet2 with same function.
    So i copy the button from sheet1, it works only if i click it from sheet1, but not sheet2. Whenever, i click it, it will show merged cell error or something.

    Excel pointed this sheet1's cell (in red fonts) error.

    Please Login or Register  to view this content.
    Even i delete it, it will show error again on the following contents clearing.

  6. #6
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    I run your code and could not find any error. The code works as it intends, but you could add this line to prevent from error occuring.
    Sub NextScreening()
    On Error Resume Next

  7. #7
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Ya, command button on sheet1, is working fine. But command button on Sheet2 error with merged cell. I tried on the line you mentioned above. When i click on the command button on sheet2, it dont clear of the error cells.

  8. #8
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    hi cychua, if we talk of sheet "Agent-Air", cells d20:d24 are merged. To avoid that error you can change this line:

    Please Login or Register  to view this content.
    to

    Please Login or Register  to view this content.

  9. #9
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    I do not know which button on sheet1 you are reffering, but I run your code line by line and do not get an error.
    You could try it yourself. Alt+F8 will take to module section, you then take your curson to the code you are trying to test it, While the cursor is inside the code, your press F8. It will go down line by line up the end. If there is an error on the code, it will stop it.
    You could also unmerge the culprit range only
    For e.g
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Hi Watersev
    I got no issue on "Agent-Sea"/Sheet1" 's command button.
    When i click on the command button on "Agent-Air/Sheet2" 's command button, it showed error on cell merging.

    Just curious to ask, i have coded it as below,
    Please Login or Register  to view this content.
    Isnt VB only refer to "Agent-Sea/Sheet1"? Instead of determine from "Agent-Air/Sheet2"

    Just hope to learn more on this. To avoid future error like this again.

  11. #11
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Sorry to get you confunse AB33.

    Sheet1, i meant is "Agent-Sea"
    Sheet2, is "Agent-Air".

  12. #12
    Forum Expert
    Join Date
    11-29-2010
    Location
    Ukraine
    MS-Off Ver
    Excel 2019
    Posts
    4,168

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    @cychua,

    if you explicitly specify sheet then it takes range from there, otherwise without specifying sheet VB understands it as the range reference on the sheet currently being active

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    No, there is nothing wrong with this line

    Please Login or Register  to view this content.
    You could also write this section like below as you did with the rest of your code.
    I can see you have a button on sheet 2 callled "Save and Clear". is this button liked to other codes in your module?

    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    08-28-2012
    Location
    Klang, Malaysia
    MS-Off Ver
    Excel 2007
    Posts
    113

    Re: VB:ClearContents Error on Merged Cell - But I dont have Any Merged Cell

    Yeah, AB33. Now i understand. Nothing wrong on my code.

    Just that the code :-
    Please Login or Register  to view this content.
    It started to clear from "Sheet2/Agent-Air", as i didnt specific which Sheet on the 1st sentence. Before that i thought that after +1. VB will maintain on "Sheet1/Agent-Sea" to start clearing.

    After AB33, lighten me on this! only i realized.

    Great great thanks to you, AB33.
    Same goes to Watersev, who pointed out my issue right to the point. Just that i still in misery and confuse.

    Appreciate for both of you, on giving hand and advice. Thanks alot.
    Last edited by cychua; 01-24-2013 at 06:36 AM.

+ 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