Dynamic Text to Columns, Loop through columns

jacobrcotton

Board Regular
Joined
Jan 28, 2017
Messages
51
Hi,

I have a series of data that, essentially, only needs to be "refreshed" before that data can be run through a new macro. IE, a macro go through each cell and {F2}+{ENTER}. But that takes too long, so i've written a macro that will go through each column and do a TextToColumn, simply without any criteria so that all it will do is refresh the data. and its great! but its also broken...code below

Based on the error thrown by VBA, its bugging out on the TextToColumns due to an invalid Range in the first line of the TextToColumns code. But Range(row,column) has never failed me before...i dont think.

Any assistance would be helpful.

Thanks!

Code:
Sub DataRefresh()


    Dim col As Integer
    
    col = 1
    
    Do Until col > 100
        
    Range(Cells(1, col), Cells(100000, col)).Select
    Selection.TextToColumns Destination:=Range(Cells(1, col)), DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
        Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
        :=Array(1, 1), TrailingMinusNumbers:=True


    col = col + 1


    Loop
    
    Range("A1").Select


End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Try this:

Code:
Sub DataRefresh()




Dim col As Integer

col = 1

Do Until col > 100

Columns("A:A").Select
Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _
TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=True, Tab:=True, _
Semicolon:=True, Comma:=True, Space:=True, Other:=True, FieldInfo:=Array(Array(1, 2), Array(2, 1)), TrailingMinusNumbers:=True


Loop
End Sub
 
Upvote 0
Maybe
Code:
Sub DataRefresh()
   Dim col As Long

   For col = 1 To 100
      Columns(col).TextToColumns Destination:=Cells(1, col), DataType:=xlDelimited, _
         TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, _
         Semicolon:=False, Comma:=False, Space:=False, Other:=False, FieldInfo _
         :=Array(1, 1), TrailingMinusNumbers:=True
   Next col

   Range("A1").Select
End Sub
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top