Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

come valorizzare una formula dinamica da vba?

1 view
Skip to first unread message

sviluppo

unread,
Apr 7, 2008, 10:26:59 AM4/7/08
to
salve,
la mia esigenza consiste nel valorizzare dinamicamente un campo formula in
un isieme di righe.
In altre parole,considerato un insieme di righe ottenuto da una query in
vba,queste righe vengono riportate in un file excel.
una delle colonne nel file excel la devo calcolare come formula in base ai
valori che ho esportato da vba,e non posso calcolarla a priori.
come fare per ,ad esempio mettendo in un ciclo while la valorizzazione del
campo formula,far capire al campo formula quali campi deve considerare?
es.
'IMPOSTA FORMULA
Dim i As Integer
i = 1
For i = 1 To 3
F.Cells(i, 5).Formula = "=Sum(i2:i3)" ' MA COSI NON FUNZIONA
Next i

vorrei cioe che le celle
(1,5)=sum(A2:A3)
(2,5)=sum(B2:B3)
(3,5)=sum(C2:C3)

spero di essere stato chiaro,grazie


Norman Jones

unread,
Apr 7, 2008, 10:59:16 AM4/7/08
to
Ciao Sviluppo,

=================

=================

Se vuoi utilizzare un ciclo, prova
qualcosa del genere:

'=============>>
Public Sub Tester()
Dim Rng As Range
Dim sumRng As Range
Dim WB As Workbook
Dim SH As Worksheet
Dim i As Long

Set WB = Workbooks("Pippo.xls") '<<==== da CAMBIARE
Set SH = WB.Sheets("Foglio1") '<<==== da CAMBIARE
Set Rng = SH.Range("E1:E3")

With Rng
For i = 1 To .Cells.Count
Set sumRng = Range("A2:A3").Offset(0, i - 1)
.Cells(i).Formula = "=Sum(" & sumRng.Address & ")"
Next i
End With

End Sub
'<<=============


---
Regards,
Norman


sviluppo

unread,
Apr 7, 2008, 11:18:54 AM4/7/08
to
forse ho risolto cosi,o meglio quasi risolto,

'IMPOSTA FORMULA
Dim i As Integer
i = 1
For i = 1 To 3
F.Cells(i, 5).Formula = "=Sum(" & i & "2:" & i & "3)" '"=$A$4+$A$10"
'"=Sum(i2:i3)"
F.Cells(i, 5).Font.Bold = True ' IMPOSTA IL GRASSETTO

Next i

ora il problema che ho č:
come rappresentare le celle anziche nella forma "A1",nella forma
"11",ammesso che si possa fare?

"Norman Jones" <norma...@whereforartthou.com> ha scritto nel messaggio
news:uxAL6AMm...@TK2MSFTNGP03.phx.gbl...

Norman Jones

unread,
Apr 7, 2008, 12:20:39 PM4/7/08
to
Ciao Sviluppo,

Prendi, gentilmente, (almeno) un passo indietro
e spiegarci la destinazione di questo viaggio e il
motivo per il viaggio.

Avevi richiesto:

===============
[...]


>> vorrei cioe che le celle
>> (1,5)=sum(A2:A3)
>> (2,5)=sum(B2:B3)
>> (3,5)=sum(C2:C3)
===============

e ti ho dato un codice adatto.
Ora tu chiedi:

===============


ora il problema che ho č:
come rappresentare le celle anziche nella forma "A1",nella forma
"11",ammesso che si possa fare?

===============

Priima di procedere, credo sia oppotuno
capire l'obiettivo.


---
Regards,
Norman


sviluppo

unread,
Apr 8, 2008, 9:44:01 AM4/8/08
to
grazie per la tua gentilezza,ho comunque risolto creando all'interno del
while sia la condizione SE,sia considerando i campi che mi
interessavano,cosi:
'questo č un esempio
R = 2 'INIZIALIZZO LA RIGA in excel
rs.CursorLocation = adUseServer
rs.Open strQry, CurrentProject.Connection, adOpenForwardOnly,
adLockOptimistic
While Not rs.EOF
F.Cells(R, 1) = rs("auto")
F.Cells(R, 2) = rs("targa")
F.Cells(R, 3) = rs("Prezzo")
If F.Cells(R - 1, 1) & F.Cells(R - 1, 2) = F.Cells(R, 1) &
F.Cells(R, 2) Then 'SE LE RIGHE SI RIFERISCONO ALLO STESSO PRODOTTO
F.Cells(R, 5) = F.Cells(R, 3) + F.Cells(R - 1, 3) 'SOMMO IL
CAMPO DEL RIGO PRECEDENTE
Else
F.Cells(R, 5) = F.Cells(R, 3)
End If

R=R+1
rs.movenext
wend

"Norman Jones" <norma...@whereforartthou.com> ha scritto nel messaggio

news:OiVAYuMm...@TK2MSFTNGP02.phx.gbl...

0 new messages