Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 16
Default Macro for text to column

Hi Everyone,
I have the macro below that splits the cell content of column D. However, this only works for those values in column D (Destination:=Range("D1")). I have tried a few things but can't get it right, I want the macro to run on any column I choose and not just Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"), DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)), TrailingMinusNumbers:=True
End Sub

Thank you

Garry
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default Macro for text to column

hi
this is what is restricting it to D.
Destination:=Range("D1")
change to...
Destination:=selection.offset(0,1)

note: make sure that your column next to your target column is blank for
text to columns will overwrite data.

Regards
FSt1

"Garrystone" wrote:


Hi Everyone,
I have the macro below that splits the cell content of column D.
However, this only works for those values in column D
(Destination:=Range("D1")). I have tried a few things but can't get it
right, I want the macro to run on any column I choose and not just
Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)),
TrailingMinusNumbers:=True
End Sub

Thank you

Garry




--
Garrystone

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for text to column

Maybe something like:

Option Explicit
Sub Split_Cells()

Dim myRng As Range

With ActiveSheet
Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection.Cells(1).EntireColumn, .UsedRange)
On Error Resume Next
End With

If myRng Is Nothing Then
MsgBox "Nothing to do!"
Exit Sub
End If

myRng.TextToColumns Destination:=myRng.Cells(1), _
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)), _
TrailingMinusNumbers:=True

End Sub



Garrystone wrote:

Hi Everyone,
I have the macro below that splits the cell content of column D.
However, this only works for those values in column D
(Destination:=Range("D1")). I have tried a few things but can't get it
right, I want the macro to run on any column I choose and not just
Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)),
TrailingMinusNumbers:=True
End Sub

Thank you

Garry

--
Garrystone


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default Macro for text to column

I think it puts the parsed data back in column D--well, that's the way I read
the post.

If that's the case, then maybe:
Destination:=selection

FSt1 wrote:

hi
this is what is restricting it to D.
Destination:=Range("D1")
change to...
Destination:=selection.offset(0,1)

note: make sure that your column next to your target column is blank for
text to columns will overwrite data.

Regards
FSt1

"Garrystone" wrote:


Hi Everyone,
I have the macro below that splits the cell content of column D.
However, this only works for those values in column D
(Destination:=Range("D1")). I have tried a few things but can't get it
right, I want the macro to run on any column I choose and not just
Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)),
TrailingMinusNumbers:=True
End Sub

Thank you

Garry




--
Garrystone


--

Dave Peterson
  #5   Report Post  
Junior Member
 
Posts: 16
Default

Thanks FSt1
Worked fine, I just needed to alter the offset to 0,0 since in my spreadsheet I am overwriting the initial column.

Thanks again

Garry

Quote:
Originally Posted by FSt1 View Post
hi
this is what is restricting it to D.
Destination:=Range("D1")
change to...
Destination:=selection.offset(0,1)

note: make sure that your column next to your target column is blank for
text to columns will overwrite data.

Regards
FSt1

"Garrystone" wrote:


Hi Everyone,
I have the macro below that splits the cell content of column D.
However, this only works for those values in column D
(Destination:=Range("D1")). I have tried a few things but can't get it
right, I want the macro to run on any column I choose and not just
Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)),
TrailingMinusNumbers:=True
End Sub

Thank you

Garry




--
Garrystone


  #6   Report Post  
Junior Member
 
Posts: 16
Default

Hi Dave
Both of the solutions worked in this post. however, I like the usage of the error and message box, thanks very much.

Garry

Quote:
Originally Posted by Dave Peterson View Post
I think it puts the parsed data back in column D--well, that's the way I read
the post.

If that's the case, then maybe:
Destination:=selection

FSt1 wrote:

hi
this is what is restricting it to D.
Destination:=Range("D1")
change to...
Destination:=selection.offset(0,1)

note: make sure that your column next to your target column is blank for
text to columns will overwrite data.

Regards
FSt1

"Garrystone" wrote:


Hi Everyone,
I have the macro below that splits the cell content of column D.
However, this only works for those values in column D
(Destination:=Range("D1")). I have tried a few things but can't get it
right, I want the macro to run on any column I choose and not just
Column D. Can anybody help?

Sub Split_Cells()

ActiveCell.EntireColumn.Select
Selection.TextToColumns Destination:=Range("D1"),
DataType:=xlFixedWidth, _
FieldInfo:=Array(Array(0, 1), Array(1, 1)),
TrailingMinusNumbers:=True
End Sub

Thank you

Garry




--
Garrystone


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Return text in Column A if Column B and Column K match jeannie v Excel Worksheet Functions 4 December 13th 07 07:36 PM
Text to column macro Anthony Excel Discussion (Misc queries) 2 December 5th 06 05:09 AM
Macro to find text string in a column and paste data in another nicolascap Excel Discussion (Misc queries) 8 March 14th 06 03:13 PM
text to column macro hioncaffiene Excel Worksheet Functions 3 February 14th 06 02:09 PM
Wrap text in column headers to fit text in column MarkN Excel Discussion (Misc queries) 10 November 11th 05 04:21 AM


All times are GMT +1. The time now is 05:41 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"