vba, flip it over the pattern

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hello people
with this code,
VBA Code:
Sub rur()
      For i = 1 To 5
            For j = 1 To 5
                  Cells(i, j) = i
            Next
      Next
End Sub
I got this
1618707858247.png


how can I get
1618707948542.png

Thank for reading.
Please, some help in this.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Hi,​
according to Excel basics it could be achieved without looping, anyway :​
VBA Code:
Sub Demo1()
    For R& = 1 To 5:  [A:E].Rows(R).Value2 = 6 - R:  Next
End Sub
 
Upvote 0
Your respond is appreciated,
would be real helpful for me
IF---in case is possible for you
be able to see the translation from
VBA Code:
'for(i=5;i>=1,i--)
'for(j=5;j>=1,j--)
'print("%d",i)
to the VBA language. Please
IF, you don't mind
 
Upvote 0
Something like For i = 5 To 1 Step -1 - to see in VBA help - but this logic obviously not well fits your initial post …​
 
Upvote 0
VBA Code:
Dim myArray() as Variant
With SomeRange
    Redim myArray(1 to .Rows.Count, 1 To .Columns.Count)
    For i = 1 to .Rows.Count
        For j = 1 to .Columns.Count
            myArray(.Rows.Count - i + 1, j) = .Cells(i, j).Value
        Next j
    Next i

    .Value = myArray
End With

There is no in-place looping that won't require a temporary storage location.
 
Upvote 0
Or according to the initial post obviously :​
Rich (BB code):
      For i = 1 To 5
      For j = 1 To 5
          Cells(i, j) = 6 - i
      Next j, i
 
Upvote 0
Solution
I'm guessing your goal is to understand looping, but if your goal is simply to produce the output you showed no matter the method, then you could consider this...
VBA Code:
Sub MonteCarlo2012()
  [A1:E5] = [{5;4;3;2;1}]
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,752
Messages
6,180,742
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