how to automatically accept a popup message when separating data into columns using VBA?

40 Views Asked by At

I am trying to separate a data in a cell into columns, I do it with vba but when running the code a popup message shows up asking me to accept, I don't need to accept something since I'm running the code to get what I want. this is the code:

Sub Separaren4()

 Range("AZ3").TextToColumns Destination:=Range("AZ3"), 
 DataType:=xlFixedWidth, _
 FieldInfo:=Array(Array(0, 1), Array(9, 1), Array(19, 1), Array(29, 1)), _
 TrailingMinusNumbers:=True

End Sub

enter image description here

2

There are 2 best solutions below

0
Hasib_Ibradzic On

Try adding

Application.EnableEvents = False

before your code and set it to True after.

Sub Separaren4()
Application.EnableEvents = False
 Range("AZ3").TextToColumns Destination:=Range("AZ3"), 
 DataType:=xlFixedWidth, _
 FieldInfo:=Array(Array(0, 1), Array(9, 1), Array(19, 1), Array(29, 1)), _
 TrailingMinusNumbers:=True
Application.EnableEvents = True
End Sub
0
DisplayName On

Clear the field before occupying it

Sub Separaren4()
    With Range("AZ3")
        .Resize(,4).EntireColumn.Clear 
        .TextToColumns Destination:=.Cells, DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 1), Array(9, 1), Array(19, 1), Array(29, 1)), TrailingMinusNumbers:=True
   End With
End Sub