Formula in a coloum

F

franco monte

I have this code

UltimaRiga = Range("A65356").End(xlUp).Row
For i = 3 To UltimaRiga
Range("G" & i).Value = (Range("D" & i).Value - Range("I" &
i).Value)
Range("G" & i).NumberFormat = "0_ ;[Red]-0 "
Next i

but I think is better (faster) without loop, is it possible?
Thanks in advance!
 
D

Dave Peterson

You could fill the range with a formula, then convert those formulas to values:

Dim UltimaRiga as long
Dim myRng as range
With worksheets("Sheet1")
unltimariga = .cells(.rows.count,"A").end(xlup).row
set myrng = .range("G3:G" & ultimariga)
with myrng
.numberformat = "0_ ;[Red]-0 "
.formula = "=D3-I3"
.value = .value
end with
end with


franco said:
I have this code

UltimaRiga = Range("A65356").End(xlUp).Row
For i = 3 To UltimaRiga
Range("G" & i).Value = (Range("D" & i).Value - Range("I" &
i).Value)
Range("G" & i).NumberFormat = "0_ ;[Red]-0 "
Next i

but I think is better (faster) without loop, is it possible?
Thanks in advance!
 
F

franco monte

Dave, can Yuo tell me what riferiments I nedd?
on the line Set myRng = .Range("G3:G" & UltimaRiga)
I have the error: Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
Thanks in advance
 
F

franco monte

Dave, can You tell me what riferiments I need?
On the line Set myRng = .Range("G3:G" & UltimaRiga) I have the error:
Errore di run-time '1004'.
Errore definito dall'applicazione o dall'oggetto.
Thanks in advance!
 
F

franco monte

Dave, it seems work correct, is it right for you?

With Range("G3:G" & UltimaRiga)
.NumberFormat = "0_ ;[Red]-0 "
.Formula = "=D3-I3"
.Value = .Value
End With
 
D

Dave Peterson

Try fixing my typo.

I spelled ultimariga incorrectly on one of those lines.
 
D

Dave Peterson

After the typo correction, it worked fine.

If you want to double check the formulas first, just comment that
".value = .value" line.



franco said:
Dave, it seems work correct, is it right for you?

With Range("G3:G" & UltimaRiga)
.NumberFormat = "0_ ;[Red]-0 "
.Formula = "=D3-I3"
.Value = .Value
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top