Hi,
I have some experience in Excel but I am a beginner in VBA.
So, I hope you will not be angry that I have the following problem.
Suppose you have a matrix which is stored in sheet "UI"
line no.2 nuklid1 0
line no.3 nuklid2 2,00E10
line no.4 nuklid3 3,00E10
line no.5 nuklid4 0
line no.6 nuklid5 5,00E10
The other table (the active sheet is DOSES):
line no. 6 nuclides distance1 distance2 distance3
line no. 7 500 1000 1500
line no. 8 nuklid1 1,00E-11 1,00E-12 1,00E-13
line no. 9 nuklid2 2,00E-11 2,00E-12 2,00E-13
line no.10 nuklid3 3,00E-11 3,00E-12 3,00E-13
line no.11 nuklid4 4,00E-11 4,00E-12 4,00E-13
line no.12 nuklid5 5,00E-11 5,00E-12 5,00E-13
UnitDose 3,8 0,38 0,038
With help of the macro recorder i got the results in the UnitDose line:
Summing the products UI!B2 * B8 + ... UI!B6 * B12 for each distance
gives 3,8 0,38 0,038.
If have the problem to automate and simplify the following VBA macro:
Later on I will have more distances (more distance rows) to consider and perhaps much more nuclide rows.
MY QUESTIONS:
Is it possible to use some loop procedure and cell indexing (cell(i,j)
which simplifies the ActiveCell.FormulaR1C1 line.
How the macro has to be rewritten to
- loop over the various distances (1 to 3)
- cover the SUMPRODUCT formula give below in a cell(i,j) notation instead
using the R1C1 properties. I think I must have the sumproduct formula
in a cell(i,j) notation to be able to loop.
Sub macroff()
'
' macroff Makro
' Makro from 04.09.2003
'
'
ActiveCell.Offset(0, 1).Range("A1"
.Select
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C2:R12C2)"
ActiveCell.Offset(0, 1).Range("A1"
.Select
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C3:R12C3)"
ActiveCell.Offset(0, 1).Range("A1"
.Select
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C4:R12C4)"
ActiveCell.Offset(0, 1).Range("A1"
.Select
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C5:R12C5)"
' ActiveCell.Offset(0, 1).Range("A1"
.Select
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C6:R12C6)"
' ActiveCell.Offset(0, 1).Range("A1"
.Select
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C7:R12C7)"
' ActiveCell.Offset(1, 0).Range("A1"
.Select
End Sub
Any help is appreciated.
Thanks
Friedmar
I have some experience in Excel but I am a beginner in VBA.
So, I hope you will not be angry that I have the following problem.
Suppose you have a matrix which is stored in sheet "UI"
line no.2 nuklid1 0
line no.3 nuklid2 2,00E10
line no.4 nuklid3 3,00E10
line no.5 nuklid4 0
line no.6 nuklid5 5,00E10
The other table (the active sheet is DOSES):
line no. 6 nuclides distance1 distance2 distance3
line no. 7 500 1000 1500
line no. 8 nuklid1 1,00E-11 1,00E-12 1,00E-13
line no. 9 nuklid2 2,00E-11 2,00E-12 2,00E-13
line no.10 nuklid3 3,00E-11 3,00E-12 3,00E-13
line no.11 nuklid4 4,00E-11 4,00E-12 4,00E-13
line no.12 nuklid5 5,00E-11 5,00E-12 5,00E-13
UnitDose 3,8 0,38 0,038
With help of the macro recorder i got the results in the UnitDose line:
Summing the products UI!B2 * B8 + ... UI!B6 * B12 for each distance
gives 3,8 0,38 0,038.
If have the problem to automate and simplify the following VBA macro:
Later on I will have more distances (more distance rows) to consider and perhaps much more nuclide rows.
MY QUESTIONS:
Is it possible to use some loop procedure and cell indexing (cell(i,j)
which simplifies the ActiveCell.FormulaR1C1 line.
How the macro has to be rewritten to
- loop over the various distances (1 to 3)
- cover the SUMPRODUCT formula give below in a cell(i,j) notation instead
using the R1C1 properties. I think I must have the sumproduct formula
in a cell(i,j) notation to be able to loop.
Sub macroff()
'
' macroff Makro
' Makro from 04.09.2003
'
'
ActiveCell.Offset(0, 1).Range("A1"
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C2:R12C2)"
ActiveCell.Offset(0, 1).Range("A1"
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C3:R12C3)"
ActiveCell.Offset(0, 1).Range("A1"
ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C4:R12C4)"
ActiveCell.Offset(0, 1).Range("A1"
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C5:R12C5)"
' ActiveCell.Offset(0, 1).Range("A1"
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C6:R12C6)"
' ActiveCell.Offset(0, 1).Range("A1"
' ActiveCell.FormulaR1C1 = "=SUMPRODUCT(UI!R2C2:UI!R6C2,R[-6]C7:R12C7)"
' ActiveCell.Offset(1, 0).Range("A1"
End Sub
Any help is appreciated.
Thanks
Friedmar