vba. looping in a triangle

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hello People.

VBA Code:
Sub pr_1()
Dim Row As Integer
Dim Column As Integer
      For Row = 2 To 7
            For Column = 2 To 7
                  Cells(Row, 9).Value = Cells(Row, 9).Value + Cells(Row, Column).Value
            Next
      Next
End Sub
With this code I got this:
1618335666977.png

Adding row by row and results on "I".
I am looking for adding just the triangle, here just for illustration and simplicity is the number 5 but could be any value, so the expecting results would be
1618336067236.png

so. what I have to change in order to get it.
I appreciate you reading this,
would be nice if someone give me a hand here.
Please.
 
Hi,​
as it can be easily achieved with a beginner level formula​
so if really a code is necessary just with a single VBA codeline like for example [I2:I7] = [$B$2*(ROW(I2:I7)-1)] …​
 
Upvote 0

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
mikerickson the Great, thank you. The goal here is the shape, any value inside the triangle will be in any mathematical operation, that's the goal.
I am trying from printing patterns, to operate inside the pattern.
Thank you again, Mr. mikerickson.
 
Upvote 0
Hi, Mr. Mark.
The goal here, or better lets use the word Target.
the target here is the logic, just remember that. For me it is not the destination, is the journey.
From your post, you use words like -- easy, beginner, level, really, necessary just, I got the picture
you are standing in a bridge watching me struggling in a big river, so from there you JUST tell me, is so easy just swim,
but you don't know if I am sick, or I don't know how to swim, and you don't have ropes,
so for me the logic is the ropes to help, no just to point out the level of knowledge.
just a little example of my journey.
It is beatiful for me to see for example in this simple diagonal

1618415407445.png

VBA Code:
Sub pptt()
Dim R%, C%
      For R = 1 To 5
            
                     Cells(R, R).Value = "R" & R
            
      Next R
End Sub
how a normal human realize the line Cells(R, R) I know is basic, ordinary for you
but to know that this person have in from of his/her eyes something like this
1618415668163.png

and base on the observation the address of the row is equal to the column address then I can try to write the same letter,
thats what is great, when somebody have the kindness to talk like this, or explain this way. All those single lines you mention, must have an explanation (no magic, no miracles)
so I always think that when somebody are resolving coding problems, I don't know what they have in front of them, I mean a board, a poster, or maybe 3 monitor, good notes,
who knows, but share is what make somebody to be great.

All fingers are not same in length but when they are bent all stands equal. Life becomes easy when we bend and adjust to situations.​

Thanks and have a nice day,
 
Upvote 0
In fact according to the great Logic my post #11 follows exactly the same journey than post #10, so close to posts #2, 7 & 8 …​
Should I mention this formula was found by a beginner kid ?​
And more easy with a smart worksheet using 0 - or any character different than a number ! - rather than 1 obviously …​
 
Upvote 0
according to the great Logic my post #11
so close to posts #2, 7 & 8 …
Just curious, how was it remotely close to all those? you may have achieved the same/similar results with the sample data, because of the sum or multiply operation.
But if you looked at the question, OP wants to loop in that triangular shape, OP shown some sample data to give a visualization, but no where was it mentioned to sum or multiply all those numbers. OP just wants the logic for looping that shape, any other operations or what will be done with the loop was not mentioned at all, and it should not be assumed.

Edit: well, it seems 'Adding' was mentioned, but I focused more on the title. I stand corrected after rereading.
 
Last edited:
Upvote 0
As my sample just follows the initial post with column I as the exepected result, just well read it !​
Post #14 changes the initial rules …​
 
Upvote 0

Forum statistics

Threads
1,224,760
Messages
6,180,816
Members
452,996
Latest member
nelsonsix66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top