Creating a Button to add to existing values while subtracting range

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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 said:
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.
 
Back
Top