VBA: Explain the symbol ► * ◄ in loops

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hello everybody.
I need a real enlightenment here. I am reading about loops and I founded three lines in different codes that in the places I founded for some reason they explain everything except this symbol. ► * ◄.
and the lines that give me hard time to understand are:

VBA Code:
EXAMPLE 1:
'Cells(8 + I, 2).Value = (term ^ 2 + (6 * term) + 1) / ((9 * term) + 7)


EXAMPLE2:
'Application.sum(range(cells(I, 2 + (j – 1) * 12.cells(I, j *12)))


EXAMPLE3:
'Cells(I + 2, “F”).formula =”=Average(A” & (I + 2) + (I * 8) & “:A” & (I + 6) +(I * 8) & “)”
So far I understand the job this symbol * are doing is like separator, "I am really not sure"
please,
Can you tell me Where to find explanation or theory, When to use, How to use and maybe Why.

thank you for reading this. see you.
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Do you mean the multiplication symbol......"*"
 
Upvote 0
That symbol is an asterisk. It represents a multiplication operator. So, for example,
Cells(I, j*12) is the cell at the intersection of row I and column j*12. If I is say 4 and j is say 2, that would be the cell X4 (row 4 and column 24).
 
Upvote 0
So far I understand the job this symbol * are doing is like separator, "I am really not sure"

In all the examples you put the asterisk is used to multiply a variable by a number.

When to use the asterisk :unsure: depends on what you want to solve. In other words, there is no fixed rule.

VBA Code:
  'EXAMPLE 1:
  Cells(8 + i, 2).Value = (term ^ 2 + (6 * term) + 1) / ((9 * term) + 7)
  'assuming  i = 3 and term = 5 
  Cells(8 + 3, 2).Value = (5 ^ 2 + (6 * 5) + 1) / ((9 * 5) + 7)
  'then
  Cells(11, 2).Value = (25 + (30) + 1) / ((45) + 7)
  'then
  cell B11 = (25 + (30) + 1) / ((45) + 7)
  'then
  cell B11 = (56) / (52)
  'then
  cell B11 = (56) / (52)
  'then
  cell B11 = 1.076923
 
Upvote 0
Thanks Dante, Joe and Michael.
in this line
Application.sum(range(cells(I, 2 + (j – 1) * 12.cells(I, j *12))) the code add every 12 column that why I realize here is not a multiplication is more like a separator.
VBA Code:
For j = 1 To 3
            For i = 2 To Cells(Rows.Count, Columns(2 + (j - 1) * 12).Address).End(xlUp).Row
                Cells(i, 39 + j).Value = Cells(i, 39 + j).Value + Application.Sum(Range(Cells(i, 2 + (j - 1) * 12), Cells(i, j * 12)))
            Next i
        Next j

and here
=Average(A” & (I + 2) + (I * 8) & “:A” & (I + 6) +(I * 8) & “)” the book shows an average every 8 rows. that's why I got confuse

Thank you dante for all the examples, now I can sleep on peace.:biggrin:
 
Upvote 0
code add every 12 column that why I realize here is not a multiplication is more like a separator.

From my point of view, first do a multiplication.
I don't see it as a "separator", rather, you are using it to get the column number.

Let's see what it does

Rich (BB code):
  'When j = 1 and i = 2
      Cells(i, 39 + j).Value = Cells(i, 39 + j).Value + Application.Sum(Range(Cells(i, 2 + (j - 1) * 12), Cells(i, j * 12)))
      Cells(2, 39 + 1).Value = Cells(2, 39 + 1).Value + Application.Sum(Range(Cells(2, 2 + (1 - 1) * 12), Cells(2, 1 * 12)))
      Cells(2, 40).Value = Cells(2, 40).Value + Application.Sum(Range(Cells(2, 2 + (0) * 12), Cells(2, 12)))
      Cells(2, 40).Value = Cells(2, 40).Value + Application.Sum(Range(Cells(2, 2 + 0), Cells(2, 12)))
      cell AN2 = AN2 + Application.Sum(Range(Cells(2, 2), Cells(2, 12)))
      cell AN2 = AN2 + Application.Sum(Range("B2:L2"))
      
    'When j = 2 and i = 2
      Cells(i, 39 + j).Value = Cells(i, 39 + j).Value + Application.Sum(Range(Cells(i, 2 + (j - 1) * 12), Cells(i, j * 12)))
      Cells(2, 39 + 2).Value = Cells(2, 39 + 2).Value + Application.Sum(Range(Cells(2, 2 + (2 - 1) * 12), Cells(2, 2 * 12)))
      Cells(2, 41).Value = Cells(2, 41).Value + Application.Sum(Range(Cells(2, 2 + (1) * 12), Cells(2, 24)))
      Cells(2, 41).Value = Cells(2, 41).Value + Application.Sum(Range(Cells(2, 2 + 12), Cells(2, 24)))
      cell AO2 = AO2 + Application.Sum(Range(Cells(2, 14), Cells(2, 24)))
      cell AO2 = AO2 + Application.Sum(Range("N2:X2"))
      
    'When j = 3 and i = 2
      Cells(i, 39 + j).Value = Cells(i, 39 + j).Value + Application.Sum(Range(Cells(i, 2 + (j - 1) * 12), Cells(i, j * 12)))
      Cells(2, 39 + 3).Value = Cells(2, 39 + 3).Value + Application.Sum(Range(Cells(2, 2 + (3 - 1) * 12), Cells(2, 3 * 12)))
      Cells(2, 42).Value = Cells(2, 42).Value + Application.Sum(Range(Cells(2, 2 + (2) * 12), Cells(2, 36)))
      Cells(2, 42).Value = Cells(2, 42).Value + Application.Sum(Range(Cells(2, 2 + 24), Cells(2, 36)))
      cell AP2 = AP2 + Application.Sum(Range(Cells(2, 26), Cells(2, 36)))
      cell AP2 = AP2 + Application.Sum(Range("Z2:AJ2"))

Example:
varios 08jul2020.xlsm
ABCDEFGHIJKLMNOPQRSTUVWXYZAAABACADAEAFAGAHAIAJAKALAMANAOAP
1
2234567891011121415161718192021222324262728293031323334353677209341
3
Hoja2


_______________________________________________________________________________________________________________________________

Application.Sum(Range(Cells(i, 2 + (j - 1) * 12), Cells(i, j * 12)))
With that line the macro gets a starting column number and a ending column number to get a range and to make the sum of that range.
_______________________________________________________________________________________________________________________________

By the way the macro does not add 12 columns, it only adds 11 columns, I hope that is correct for you.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,322
Members
452,635
Latest member
laura12345

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