ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Creating a Button to add to existing values while subtracting range (https://www.excelbanter.com/excel-programming/292217-creating-button-add-existing-values-while-subtracting-range.html)

C. A. Zan

Creating a Button to add to existing values while subtracting range
 
Greetings Programers,

I have be looking for some samples of how to use a button with a macro to add a value (let's say minutes) entered in cell A1.

Which upon clicking the button adds the value in A1 to an existing value of (mins.) to cell A2.

Once the total in A2 is updated, range (A3:F3) of positive values are subtracted and the results are displayed in cell B1(Mins. remaining).

I know this should be a simple one. But being new to VB, I need some help on this one. I thought I saw an example of this somewhere but can't locate it.

Thank in advance,
Chris A. Z.

Bob Phillips[_5_]

Creating a Button to add to existing values while subtracting range
 
Hi Chris,

Off the top

Private Sub CommandButton1_Click()
Dim cell As Range
Range("A2").Value = Range("A1").Value
Range("B1").Value = Range("A2").Value
For Each cell in Range("A3:F3")
If cell.Value 0 Then
Range("B1").Value = Range("B1").Value - cell.Value
End If
Next cell
End Sub

But why not just do it with worksheet formula?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"C. A. Zan" wrote in message
...
Greetings Programers,

I have be looking for some samples of how to use a button with a macro to

add a value (let's say minutes) entered in cell A1.

Which upon clicking the button adds the value in A1 to an existing value

of (mins.) to cell A2.

Once the total in A2 is updated, range (A3:F3) of positive values are

subtracted and the results are displayed in cell B1(Mins. remaining).

I know this should be a simple one. But being new to VB, I need some help

on this one. I thought I saw an example of this somewhere but can't locate
it.

Thank in advance,
Chris A. Z





All times are GMT +1. The time now is 01:25 PM.

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