macro to position cursor to the next character

ashley789

New Member
Joined
Jun 21, 2002
Messages
17
hello

does someone know a macro that can position
the cursor the next letter or number.
i have a text file that has the raw info
like this :

abcd_ _ efg_ _ _ ab
ab_ _ _ _ _ _ gh

i want to skip the spaces and have excel
put "abcd" in cell a1 , "efg" in cell b1, "ab"in cell c1. The next line of information is entered with "ab" in cell a2 and cell b2 is entered with "gh".

Because the number of spaces varies between
each information and in each row, I can't the fixed width function to have excel import based on defined columns.

any help would be greatly appreciated.

ashley
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Ashley, hi, try this macro. It will work in XL 2000 or XP, since I used the Split function, that was not available in XL 97. If you have that, well, we need to create a custom Split for you (This was asked today BTW)

I assumed your data starts in row 1, and started parseing from that row.

Run the Test sub.<pre>Sub Test()
Dim i As Long
Dim FName As Variant
Dim FRange As Variant
FName = Application.GetOpenFilename("*.txt,*.txt")
If FName = False Then Exit Sub
Workbooks.OpenText FName, xlWindows, 1, xlFixedWidth, xlTextQualifierNone, FieldInfo:=Array(0, 1)

For i = 1 To Range("A65536").End(xlUp).Row
FRange = Parse(Cells(i, 1))
Cells(i, 1).Resize(1, UBound(FRange, 1)) = FRange
Next i
End Sub

Private Function Parse(ByVal Text As String) As Variant
Dim Ar As Variant
Dim Ans() As Variant
Dim i As Integer
Dim Ctr As Integer
Ar = Split(Text, " ")
For i = LBound(Ar) To UBound(Ar)
If Len(Ar(i)) > 0 Then
Ctr = Ctr + 1
ReDim Preserve Ans(1 To Ctr)
Ans(Ctr) = Ar(i)
End If
Next i
Parse = Ans
End Function</pre>

_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting
This message was edited by Juan Pablo G. on 2002-09-03 15:44
 
Upvote 0
Oh, another thing, the macro, where to put it. You can just put it in a new workbook, go to Visual Basic (Alt F11), insert a module, and paste the code there. Then, run the Test sub.
 
Upvote 0
Hi there
Perhaps you could also try from the toolbar:
Data
Text to Columns
Delimited
Check against "Space"
Check against "Treat consecutive delimiters as one"
regards
Derek
 
Upvote 0
juan,

can you show step by step on how to create
split function - i have excel 97 version.
i read the posting and wasn't able to
follow it thru.

thank you







On 2002-09-03 15:43, Juan Pablo G. wrote:
Ashley, hi, try this macro. It will work in XL 2000 or XP, since I used the Split function, that was not available in XL 97. If you have that, well, we need to create a custom Split for you (This was asked today BTW)

I assumed your data starts in row 1, and started parseing from that row.

Run the Test sub.<pre>Sub Test()
Dim i As Long
Dim FName As Variant
Dim FRange As Variant
FName = Application.GetOpenFilename("*.txt,*.txt")
If FName = False Then Exit Sub
Workbooks.OpenText FName, xlWindows, 1, xlFixedWidth, xlTextQualifierNone, FieldInfo:=Array(0, 1)

For i = 1 To Range("A65536").End(xlUp).Row
FRange = Parse(Cells(i, 1))
Cells(i, 1).Resize(1, UBound(FRange, 1)) = FRange
Next i
End Sub

Private Function Parse(ByVal Text As String) As Variant
Dim Ar As Variant
Dim Ans() As Variant
Dim i As Integer
Dim Ctr As Integer
Ar = Split(Text, " ")
For i = LBound(Ar) To UBound(Ar)
If Len(Ar(i)) > 0 Then
Ctr = Ctr + 1
ReDim Preserve Ans(1 To Ctr)
Ans(Ctr) = Ar(i)
End If
Next i
Parse = Ans
End Function</pre>

_________________
Regards,

Juan Pablo G.
MrExcel.com Consulting
This message was edited by Juan Pablo G. on 2002-09-03 15:44
 
Upvote 0
Ashley, I would suggest the other approach, using Text To Columns checking "Treat consecutive delimiters as one" in the second step. That would be far more efficient than my macro approach.
 
Upvote 0

Forum statistics

Threads
1,214,566
Messages
6,120,257
Members
448,952
Latest member
kjurney

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