Updating Text to column Fieldinfo:= using loop

pranav_d

New Member
Joined
Jan 26, 2022
Messages
3
I am trying to pull array info from FYI sheet so that I can change breaks as needed and then do text to column on Data tab. But it is not working getting Run time error. Can you help me how to get break points from one sheet and then apply text to column in second sheet with data?

Sub txtclm()

Sheets("FYI").Select

a = "Array(Array(0, 2),"

c = Cells(2, 1).End(xlDown).Row

For i = 2 To c

If i <> c Then
a = a & " Array(" & Cells(i, 2) & ", 2),"
Else
a = a & " Array(" & Cells(i, 2) & ", 2))"
End If
Next i

Sheets("Data").Select

Range("A:A").TextToColumns Destination:=Range("A1"), DataType:=xlFixedWidth, _
FieldInfo:=a
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
can you give 5 lines of your data
this is almost correct, but i can't test it.
in AA1:AB9 you have the numbers, you want to use
VBA Code:
Sub txtclm()
     With Sheets("FYI")
          a = Application.Transpose(Evaluate("=" & .Range("AA1:AB9").Address))
          .Range("A1:A10").TextToColumns Destination:=.Range("b1"), DataType:=xlFixedWidth, FieldInfo:=a
     End With
End Sub

Map4
ZAAABAC
102
232
382
4142
5222
6302
7382
8442
9512
10
Blad4
 
Upvote 0
I tried but it is not working. Lets suppose first tab "Data" has values as aaaa, bbbb, cccc, dddd and break points are in second tab from cell B2 are 1, 2, 3, 4 etc., so I want macro to separate a in each column a a a a. You can see below in macro screenshot that Arrays are getting created by loop but Fieldinfo:= is not accepting it.
 

Attachments

  • Data.JPG
    Data.JPG
    14.3 KB · Views: 10
  • FYI.JPG
    FYI.JPG
    16.7 KB · Views: 10
  • Macro.JPG
    Macro.JPG
    43.4 KB · Views: 11
Upvote 0
try this with an empty sheet
VBA Code:
Sub Pranav()

     iNumber = 26

     Dim FI()                                                   'declare FieldInfo-array
     ReDim FI(1, iNumber - 1)                                   'redim(1 less then then number of characters)
     For i = 0 To UBound(FI, 2)                                 'loop
          FI(0, i) = i                                          '1st form 0 to inumber-1(=position of the width
          FI(1, i) = 1                                          'general
     Next

     With Range("B1:B180")
     'preparation of the data to separate
          .Offset(, -1).FormulaR1C1 = "=REPT(CHAR(ROW()+64)," & iNumber + 5 & ")"     'so many characters as iNumber + 5 extra
          .Value = .Offset(, -1).Value                          'the value of that formula

msgbox "ready ?"     
'real stuff
          Application.DisplayAlerts = False
          .TextToColumns Destination:=.Cells(1, 2), DataType:=xlFixedWidth, FieldInfo:=Application.Transpose(FI)     ' 'separate the B-column to the C-column and following columns, 1 character width
          Application.DisplayAlerts = True

     End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,054
Messages
6,122,893
Members
449,097
Latest member
dbomb1414

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