简体   繁体   中英

VBA Macro not working for certain cells

I currently export information into Excel on a daily basis. Certain days of the month are missing, so I've been creating a macro to add them. The macro works fine, but I have to convert the text that excel doesn't recognise into actual text. I use "Text to Columns" for this. I created the following macro:

Sub ejemplo()
'
' ejemplo Macro
'


Dim i As Integer
i = 2

Do
Cells(1, i).Select

Selection.TextToColumns Destination:=Cells(1, i), DataType:=xlDelimited, _
    TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
    :=Array(1, 1), TrailingMinusNumbers:=True

i = i + 1
Loop Until ActiveCell = ""

End Sub

The macro works fine for the first 10 or so columns (depending on which export I am trying to use it on), but then it simply runs over the cell and performs no action. If i do it manually it works, it's only when I do it from the macro that it doesn't.

I have tried copying the information and transfering to other sheets, but nothing seems to work. The format of these cells is the same as the ones where the macro works.

I hope someone can help.

Thanks

Maybe this...

Sub Macro1()

Dim strDelimiter As String
strDelimiter = ","

    Selection.TextToColumns Destination:=ActiveCell.Range("A1"), DataType:=xlDelimited, _
    TextQualifier:=xlSingleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
    Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar:=strDelimiter, FieldInfo _
    :=Array(1, 1), TrailingMinusNumbers:=True

End Sub

I found the problem. It was the array within text to columns. Since what I was working on was dates, the array needed to be Array(1, 4) instead of Array(1, 1).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM