Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

array result

Status
Not open for further replies.

Xsi

Programmer
May 29, 2015
121
SE
Hello people,

I have made following code below:

my code loops through columns 14 to 25
and for each cell message the content

now is my question how do I msgbox the total for all elements in one row?
Code:
Sub myAr() 
     
     
    Dim mystring As Integer 
     
    For x = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).row 
        Dim j As Integer 
        For j = 14 To 25 
             
            mystring = Cells(x, j).Value 
             
        Next j 
         
         ' I for each cell above I get a value I need now to sum all the values to a total and msgbox here for each row.
    Next x 
     
     
End Sub

thank you in advance
 
HI,

My string As Integer???

How misleading!

Why not sum as you loop?



Skip,

[glasses]Just traded in my OLD subtlety...
for a NUance![tongue]
 

Code:
Sub myAr() 
    Dim mystring As Integer [blue]
    Dim MyValue As Integer[/blue]

    For x = 1 To ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).row 
        Dim j As Integer [blue]
        MyValue = 0[/blue]
        For j = 14 To 25 
            mystring = Cells(x, j).Value [blue]
            MyValue = MyValue + mystring[/blue]
        Next j 
        ' I for each cell above I get a value I need now to sum all the values to a total and msgbox here for each row.[blue]
        MsgBox "Sum for row " & x & " is: " & MyValue[/blue]

    Next x 
End Sub

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top