ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   VBA Code Bug (https://www.excelbanter.com/excel-programming/431900-vba-code-bug.html)

Jim

VBA Code Bug
 
I'm having a run time error with this code:

NewSht.Range("K72") = OldSht.Range("K69" - "K70" - "K71")

Suggestions?

Jacob Skaria

VBA Code Bug
 
Try

NewSht.Range("K72") = OldSht.Range("K69") - OldSht.Range("K70") -
OldSht.Range("K71")

OR

NewSht.Range("K72") = OldSht.Range("K69") - (OldSht.Range("K70") +
OldSht.Range("K71"))

If this post helps click Yes
---------------
Jacob Skaria


"Jim" wrote:

I'm having a run time error with this code:

NewSht.Range("K72") = OldSht.Range("K69" - "K70" - "K71")

Suggestions?


John

VBA Code Bug
 
I will assume that you are trying to subtract ranges K70, K71 from K69?

see if this way helps:

newsht.Range("K72").Value = _
oldsht.Range("K69").Value - WorksheetFunction.Sum(oldsht.Range("K70:K71"))

--
jb


"Jim" wrote:

I'm having a run time error with this code:

NewSht.Range("K72") = OldSht.Range("K69" - "K70" - "K71")

Suggestions?


Rick Rothstein

VBA Code Bug
 
Here is another way do it...

With OldSht.Range("K69")
NewSht.Range("K72").Value = .Value - .Offset(1).Value - .Offset(2).Value
End With

--
Rick (MVP - Excel)


"Jim" wrote in message
...
I'm having a run time error with this code:

NewSht.Range("K72") = OldSht.Range("K69" - "K70" - "K71")

Suggestions?




All times are GMT +1. The time now is 09:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com