+ Reply to Thread
Results 1 to 8 of 8

Sum of Len(string) for an entire row

  1. #1
    Registered User
    Join Date
    10-05-2005
    Posts
    18

    Sum of Len(string) for an entire row

    Having a hard time wrapping my head around this one as Im still rusty on the actual VB functions specific to excel...

    Im looking for vb code that will return the sum of all characters in a particular row, where the column header row (row 1) is not empty...

    Thanks in advance!

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Durex,

    Here is a Worksheet Formula Example to sum everything in row 2...

    =SUM("2:2")

    Example of summing multiple rows. Rows 2 through 10...

    =SUM("2:10")

    Example of summing a Range...

    =SUM("A2:R240")


    Hope this helps,
    Leith Ross

  3. #3
    Registered User
    Join Date
    10-05-2005
    Posts
    18
    Actually, to do what Im looking to do using an excel formula, you need to use an array formula..

    i.e.
    For Summing all characters for row 2, columns A2 through G2...
    {=SUM(LEN(A2:G2))}

    But, Im not looking for the excel formula... Im looking how to do this in vbcode.

    Thanks for the suggestion!

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Durex,

    I played it safe answering your first question. Sometimes people say VB and worksheet formula and vice versa. So, here's what to do.

    Please Login or Register  to view this content.
    To use it:

    Dim X

    X = AddRow("A1:G1")

    X = Sum of the row. At least the sum of any valid numbers in the row.


    Sincerely,
    Leith Ross

  5. #5
    Gary Keramidas
    Guest

    Re: Sum of Len(string) for an entire row

    try this
    Range("h2").FormulaArray = "=sum(len(A2:g2))"

    --


    Gary


    "durex" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Actually, to do what Im looking to do using an excel formula, you need
    > to use an array formula..
    >
    > i.e.
    > For Summing all characters for row 2, columns A2 through G2...
    > {=SUM(LEN(A2:G2))}
    >
    > But, Im not looking for the excel formula... Im looking how to do this
    > in vbcode.
    >
    > Thanks for the suggestion!
    >
    >
    > --
    > durex
    > ------------------------------------------------------------------------
    > durex's Profile:
    > http://www.excelforum.com/member.php...o&userid=27857
    > View this thread: http://www.excelforum.com/showthread...hreadid=478407
    >




  6. #6
    Gary Keramidas
    Guest

    Re: Sum of Len(string) for an entire row

    and if you need the result in a variable, this should do it

    TotalLen = Application.Evaluate("=sum(len(a2:g2))")

    --


    Gary


    "durex" <[email protected]> wrote in
    message news:[email protected]...
    >
    > Actually, to do what Im looking to do using an excel formula, you need
    > to use an array formula..
    >
    > i.e.
    > For Summing all characters for row 2, columns A2 through G2...
    > {=SUM(LEN(A2:G2))}
    >
    > But, Im not looking for the excel formula... Im looking how to do this
    > in vbcode.
    >
    > Thanks for the suggestion!
    >
    >
    > --
    > durex
    > ------------------------------------------------------------------------
    > durex's Profile:
    > http://www.excelforum.com/member.php...o&userid=27857
    > View this thread: http://www.excelforum.com/showthread...hreadid=478407
    >




  7. #7
    Ron Rosenfeld
    Guest

    Re: Sum of Len(string) for an entire row

    On Fri, 21 Oct 2005 18:30:07 -0500, durex
    <[email protected]> wrote:

    >
    >Having a hard time wrapping my head around this one as Im still rusty on
    >the actual VB functions specific to excel...
    >
    >Im looking for vb code that will return the sum of all characters in a
    >particular row, where the column header row (row 1) is not empty...
    >
    >Thanks in advance!


    One simple way to do this in code is to just step through each cell. So:

    ===============
    Function LenRow(rg As Range) As Double
    Dim c As Range
    Dim i As Long

    For Each c In rg
    LenRow = LenRow + Len(c.Text)
    Next c
    End Function
    ================


    --ron

  8. #8
    Registered User
    Join Date
    10-05-2005
    Posts
    18
    Excellent! Thanks so much! I was actually looking for the total length of all strings in a particular row, but that got me in the direction I needed! Just made a minor modification and it worked like a charm.

    Please Login or Register  to view this content.
    Just Changed the "Val" to "Len"

    Thanks again for the super fast reply!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1