Incorporate external values into existing range

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Incorporate external values into existing range

Post by VegasNath »

Incorporate external values into existing range.

Code: Select all

Dim a As Currency, b As Currency, c As Currency, d As Currency

    a = wb1.Range("I56").Value
    b = wb0.Range("I500").End(xlUp).Value
    
    c = wb1.Range("J56").Value
    d = wb0.Range("J500").End(xlUp).Value
    
    wb1.Range("I56") = sum existing value (a) & b
    wb1.Range("J56") = sum existing value (c) & d
a, b, c & d can be either positive or negative values.

I need to adjust the value in a to incorporate the value of b, likewise for c & d, as values, not formulas.

How is the best way to achieve this?
:wales: Nathan :uk:
There's no place like home.....

User avatar
mbarron
2StarLounger
Posts: 112
Joined: 25 Jan 2010, 20:19

Re: Incorporate external values into existing range

Post by mbarron »

Something like this?

Code: Select all

    wb1.Range("I56") = a+ b
    wb1.Range("J56") = c+ d
Crude mock up using only one sheet attached. Using this code assigned to the button.

Code: Select all

Sub test()
    Dim a As Integer, b As Integer, c As Integer, d As Integer
    a = Cells(1, 1)
    b = Cells(1, 2)
    c = Cells(2, 1)
    d = Cells(2, 2)
    Cells(1, 1) = a + b
    Cells(2, 1) = c + d
End Sub
You do not have the required permissions to view the files attached to this post.

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Incorporate external values into existing range

Post by VegasNath »

Thanks Mike, that works, but....

I forgot to mention that if a is positive, it should be calculated as a negative, and vice versa.

a = wb1.Range("I56").Value
b = wb0.Range("I500").End(xlUp).Value

a = 55
b = 155

wb1.Range("I56") = ??? 100
:wales: Nathan :uk:
There's no place like home.....

User avatar
HansV
Administrator
Posts: 78508
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Incorporate external values into existing range

Post by HansV »

How about

wb1.Range("I56") = b - a
Best wishes,
Hans

User avatar
VegasNath
5StarLounger
Posts: 1185
Joined: 24 Jan 2010, 12:02
Location: Wales, UK.

Re: Incorporate external values into existing range

Post by VegasNath »

Thanks, got there in the end :doh:
:wales: Nathan :uk:
There's no place like home.....