Button macro

ElevatorBoy

New Member
Joined
Jan 4, 2014
Messages
4
Hello. Am new in VBA, have some intresting idea and wanna to ask some expirienced people for help.
I want to make macro for button in sheet2, when pressed, i want to subtract value from cell A1.sheet2 in cell A1.sheet1, AND to leave resault in cell A1.sheet1. Both cells are numbers.
Is that possible?
Thanks in advence for some advice and direction how to solve this problem.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi and welcome to the Board
You could simply record the macro with the recorder and then assign it to the button, by right clicking on the button and selecting Assign macro and selecting the required macro from the list provided
 
Upvote 0
First thanks for answare in short notice. :)
Record how? I press record but dont know what to do next. Should i jump from one sheet to another and make step by step subtraction or what? I wanna keep formating of cells as number without using formulas. Sorry if am bit slow.
 
Upvote 0
once you have pressed record, you simply carry out the actions you require and they are permanently saved for future use.
 
Upvote 0
I have problem to create macro (dont know how to record this) that will do this:
SHEET 1 CELL A1 = SHEET 1 CELL A1 - SHEET 2 CELL A1, and to repeat that for some number of cells.
Trying to record one but i dont manage to do it right. Cant record action that after subtraction value is in cell A1 not formula. Your forum gived me some insights but cant find the solution.

I would program it like this:
n=1
IF value of cell A*n* is not "" THEN Sheet 1 CELL A*n*= Sheet 1 CELL A*n* - Sheet 2 CELL A*n*
n=n+1
ELSE End Sub

Because i need it for around 50 cells to be subtract.
I hope you can help me and thank you in advance.
 
Upvote 0
Maybe something like
Code:
Sub MM1()
Dim lr As Long, r As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
For r = 1 To lr
    If Range("A" & r).Value <> "" Then
        Range("A" & r).Value = Range("A" & r).Value - Sheets("Sheet2").Range("A" & r).Value
    End If
Next r
End Sub
 
Upvote 0
Pleasure...hope it's what you wanted...(y)
 
Upvote 0

Forum statistics

Threads
1,203,140
Messages
6,053,725
Members
444,681
Latest member
Nadzri Hassan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top