ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A begginer trying to use arrays (https://www.excelbanter.com/excel-programming/343904-begginer-trying-use-arrays.html)

[email protected]

A begginer trying to use arrays
 
If you were to call me a begginner you'd be over doing it. :D


Here's what I'm trying to pull of.


I have assigned book marks, in this case A, AA, AAA, then in another
cell the user will type in the names of the bookmarks
"A, AA, AAA". From there I need to cyle threw whatever bookmarks the
user has typed in and sum up 4 numbers that are placed relative to each

bookmarked cell, and print the result from each bookmark sum in another

cell.


I'm pretty darn lost...please showme the light! Thanks.


--------------------------


Option Explicit


Sub test()


Dim i As Integer


Dim valueme() As String
valueme = Split([c60], ",")


'C60 = "A, AA, AAA" - my bookmark names


For i = 0 To UBound(valueme)
valueme(i) = Trim(valueme(i))


Next i


End Sub


Dave Peterson

A begginer trying to use arrays
 
Bookmarks = range names???

First, I think you'd have to a little checking in those cells to make sure that
the user entered the valid range names, too:

Option Explicit
Sub test()

Dim i As Long
Dim TestRng As Range
Dim ValueMe As Variant
Dim myCell As Range
Dim myRng As Range
Dim mySum As Double

With ActiveSheet
Set myRng = .Range("C60:c65")
For Each myCell In myRng.Cells
mySum = 0
ValueMe = Split(myCell.Value, ",")
For i = LBound(ValueMe) To UBound(ValueMe)
Set TestRng = Nothing
On Error Resume Next
Set TestRng _
= ThisWorkbook.Names(Trim(ValueMe(i))).RefersToRange
On Error GoTo 0

If TestRng Is Nothing Then
'not a valid entry, just skip it???
Else
mySum = mySum + Application.Sum(TestRng)
End If
Next i
myCell.Offset(0, 1).Value = mySum
Next myCell
End With
End Sub

If there is an error, you may want:

If TestRng Is Nothing Then
mySum = CVErr(xlErrRef)
Exit For
Else
mySum = mySum + Application.Sum(TestRng)
End If

Just to show that it should be cleaned up before you can trust the results.



wrote:

If you were to call me a begginner you'd be over doing it. :D

Here's what I'm trying to pull of.

I have assigned book marks, in this case A, AA, AAA, then in another
cell the user will type in the names of the bookmarks
"A, AA, AAA". From there I need to cyle threw whatever bookmarks the
user has typed in and sum up 4 numbers that are placed relative to each

bookmarked cell, and print the result from each bookmark sum in another

cell.

I'm pretty darn lost...please showme the light! Thanks.

--------------------------

Option Explicit

Sub test()

Dim i As Integer

Dim valueme() As String
valueme = Split([c60], ",")

'C60 = "A, AA, AAA" - my bookmark names

For i = 0 To UBound(valueme)
valueme(i) = Trim(valueme(i))

Next i

End Sub


--

Dave Peterson

Kevin O'Neill[_2_]

A begginer trying to use arrays
 
Thanks, I'll be using bits and peaces of your code. I'm flying now!



All times are GMT +1. The time now is 12:31 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com