Consulting

Results 1 to 5 of 5

Thread: Need Help: Auto-acept To replace

  1. #1
    VBAX Newbie
    Joined
    Oct 2010
    Posts
    3
    Location

    Question Need Help: Auto-acept To replace

    Hello. First at all I am Argentinian, and I speak and write in Spanish. My apologizes for Gramatical error in your language.
    Ok. This is my situation. I am making a macro wich automatically do "TextToColumns" in an excel sheet. I know how to do it, but when I bring that commands from a "Module" to a "Form", start to appear a dialog to "Want to replace [..] the destine cell?" (buttons of Accept / Cancel), just after I give the command.

    I really want to know if are a way to avoid that message and continue with the "textToColumns" commands. Or how I can make to tell this dialog to proceed with the replacement (I donīt have anything to the right)

    This are the data I have about it:
    =====================================================
    Columns("C:C").Select
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
    Selection.Insert Shift:=xlToRight
    Range("B11:B22").Select


    Selection.TextToColumns Destination:=Range("B11"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
    TrailingMinusNumbers:=True


    Columns("E:E").Select
    Selection.Delete Shift:=xlToLeft

    Range("C10").Select
    ActiveCell.FormulaR1C1 = "Label1" '<-- just some title to the columns
    Range("D10").Select
    ActiveCell.FormulaR1C1 = "Label2" '<-- just some title to the columns
    =====================================================

    The dialog supose to appear before " Selection.TextToColumns..." line.

    Thank you so much for any help that you can give me.

    Note: If need more info, let me know.
    Note2: Here are 2 lines of the data that I have to "Encolumn":
    38 | Medi_Nor | TECO|
    35 | Medi_Sur | TECO|

  2. #2
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Welcome to VBAX,

    Add these lines to your code at the beginning to the code

    [vba]Application.DisplayAlerts = False[/vba]

    And following at the end of the code to return to default settings:
    [vba]Application.DisplayAlerts = True[/vba]

    See if it helps.

    It may be also important to know that Excel raises this message only when the cells have some content in them.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    As you work in code, try to remove the verbiage created by the recorder. Also, remove unnesessary selection. Your code will be much simpler, easier to debug/modify and faster. For your example, this reduces to

    [vba]Sub hh()

    Columns("C:E").Insert

    Range("B11:B22").TextToColumns Destination:=Range("B11"), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _
    :="|", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), Array(4, 1)), _
    TrailingMinusNumbers:=True

    Columns("E:E").Delete

    Range("C1010") = Array("Label1", "Label2") '<-- just some title to the columns

    End Sub

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    VBAX Newbie
    Joined
    Oct 2010
    Posts
    3
    Location
    Thanks shrivallabha! It works! Thanks for your time and attention, and of course: Knowledge.

  5. #5
    VBAX Newbie
    Joined
    Oct 2010
    Posts
    3
    Location
    [quote=mdmackillop]As you work in code, try to remove the verbiage created by the recorder. Also, remove unnesessary selection. Your code will be much simpler, easier to debug/modify and faster.

    Thanks mdmackillop! I am really surprise how easier it turns with your advices! And so clear.

    From now I will pay attention to remove unnecessary lines that create the recorder.

Posting Permissions

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