View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Vergel Adriano Vergel Adriano is offline
external usenet poster
 
Posts: 857
Default Interop.Excel Split and Copy

This is how I would do it in VBA. Hopefully it gives you an idea and you can
come up with a C# equivalent.

Sub test()
Dim arr As Variant
Dim rng As Range
Dim c As Range
Dim i As Integer

Set rng = ActiveSheet.Range("A:A")

For Each c In rng
If c.Value = "" Then Exit For

arr = Split(c.Value, " ")
For i = 0 To UBound(arr)
c.Offset(0, i + 1).Value = arr(i)
Next i
Next c

End Sub

--
Hope that helps.

Vergel Adriano


"krayakin" wrote:

I'm trying to create a small plugin for Excel that will take a column (the
current selected column) and split the text into seperate columns based on
spaces.

I have the code to select the current column (although it is taking the
entire column, not the used range, any suggestions on that as well would be
nice)

Code Snippet

if (Application.ActiveWindow.Selection is Excel.Range)
{
Application.ScreenUpdating = false;
Excel.Range range = Application.ActiveWindow.Selection as Excel.Range;
range = range.EntireColumn;

}


I'm not exactly sure how to proceed from here. Below is a primitive example
of what I'd like to see.


Before
|ColA |
|Foo Bar |
|smarmy |
|Split Me|


After

|ColA |ColB |
|--------|--------|
|Foo |Bar |
|smarmy | |
|Split |Me |