Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 79
Default Split function - assign to array

I am using the split function to return the arguments in sum functions, of
which there are many in each worksheet. Eg a cell with =sum(a1,a2,a3,a4), I
need to return a1 to a4 then read these into a dynamic array. Split function
returns a 1-d array but i can't work out how to read into inparray(). Help
appreciated. Thanks

Dim c As Range
Dim sht As Worksheet
Dim inparray() As String
Dim sformula As String
Dim i As Integer
Dim l As Integer


For Each sht In ActiveWorkbook.Worksheets

For Each c In sht.UsedRange.Cells

If c.HasFormula = True Then
l = Len(c.Formula) - 6
sformula = Mid(c.Formula, 6, l)
ReDim inparray(UBound(Split(sformula, ",", -1))) As String
inparray() = Split(sformula, ",", -1)
Else: End If


Next c

Next sht

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Split function - assign to array

Try the below macro...The string variable is split to an array variable...The
lower bound of the array would be 0..

Sub Macro()
Dim strData As String, arrData As Variant

strData = "a,b,c,d,e"
arrData = Split(strData, ",")

For intTemp = 0 To UBound(arrData)
MsgBox arrData(intTemp)
Next

End Sub

If this post helps click Yes
---------------
Jacob Skaria


"PBcorn" wrote:

I am using the split function to return the arguments in sum functions, of
which there are many in each worksheet. Eg a cell with =sum(a1,a2,a3,a4), I
need to return a1 to a4 then read these into a dynamic array. Split function
returns a 1-d array but i can't work out how to read into inparray(). Help
appreciated. Thanks

Dim c As Range
Dim sht As Worksheet
Dim inparray() As String
Dim sformula As String
Dim i As Integer
Dim l As Integer


For Each sht In ActiveWorkbook.Worksheets

For Each c In sht.UsedRange.Cells

If c.HasFormula = True Then
l = Len(c.Formula) - 6
sformula = Mid(c.Formula, 6, l)
ReDim inparray(UBound(Split(sformula, ",", -1))) As String
inparray() = Split(sformula, ",", -1)
Else: End If


Next c

Next sht

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Split function - assign to array


Sub test()
Dim i As Long
Dim sFml As String
Dim arrArgs() As String

sFml = "=sum(a1,a2,a3,a4)"

If Left$(UCase(sFml), 5) = "=SUM(" Then
If InStr(6, sFml, ",") Then
arrArgs = Split(Mid$(sFml, 6, Len(sFml) - 6), ",")
For i = 0 To UBound(arrArgs)
Debug.Print arrArgs(i)
Next
End If
End If
End Sub

Regards,
Peter T

"PBcorn" wrote in message
...
I am using the split function to return the arguments in sum functions, of
which there are many in each worksheet. Eg a cell with =sum(a1,a2,a3,a4),
I
need to return a1 to a4 then read these into a dynamic array. Split
function
returns a 1-d array but i can't work out how to read into inparray(). Help
appreciated. Thanks

Dim c As Range
Dim sht As Worksheet
Dim inparray() As String
Dim sformula As String
Dim i As Integer
Dim l As Integer


For Each sht In ActiveWorkbook.Worksheets

For Each c In sht.UsedRange.Cells

If c.HasFormula = True Then
l = Len(c.Formula) - 6
sformula = Mid(c.Formula, 6, l)
ReDim inparray(UBound(Split(sformula, ",", -1))) As String
inparray() = Split(sformula, ",", -1)
Else: End If


Next c

Next sht

End Sub



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
Assign function return value to an array Varun Excel Programming 2 March 12th 09 12:59 AM
Assign Values to array Jeff Excel Discussion (Misc queries) 14 July 15th 08 06:06 PM
Passing result of multiple split function results to 1 Array ExcelMonkey Excel Programming 5 January 19th 08 07:55 AM
Assign formula array in vba ManOnBar Excel Programming 0 July 21st 05 08:11 PM
How do I assign values to an array? Skyway[_2_] Excel Programming 14 February 29th 04 01:22 AM


All times are GMT +1. The time now is 10:35 PM.

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

About Us

"It's about Microsoft Excel"