Microsoft Excel subtraction using VBA

20 pts.
Tags:
Microsoft Excel
Microsoft Excel formulas
VBA
Visual Basic for Applications
I would like to have some coding in vb related to subtraction in Excel sheet.I have 2 sheets.I need to take data from 2 cells from the first sheet and perform subtraction and then placeresult in sheet2.I have huge amount of data in sheet1.I need to perform this operation with all the cells in sheet1.By clicking a button it should give all results at a time.Can you please provide me the sample code.
ASKED: April 8, 2009  11:26 AM
UPDATED: April 13, 2009  10:58 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

I am supposing that you have a data in sheet1 and you want result in sheet2. Also, the data is lying in A and B column of sheet1. So the following code will help you in achieving results.

Sub SubExample()
Dim i as long

i=1
Do while Sheet1.Cells(i,1)<>”"
Sheet2.Cells(i,1)= Sheet1.Cells(i,1)-Sheet1.Cells(i,2)

i=i+1
Loop

End Sub

Regards,
Sarfaraz Ahmed
<a href=”http://findsarfaraz.blogspot.com”>MS Excel help</a>

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Devisri
    Hi, Thank you.The basic operation is excel subtraction but the actual problem is: I have 3 excel sheets. In sheet1 I have huge amount of data in date & time(date-hourse:min:sec:millisec) formate.I need to exclude date formate and take only time formate(hourse:min:sec:millisec) and place that data in sheet2. So now In sheet2 we have number of rows from B to k and columns from 1 to 1000 all these cells consists data in time formate.I need to take all the data in B row as a reference data and subtract B row data from C row data and place all the result in sheet3.similarly perform this subtraction with each row(D,E,F...........K)by taking B as a reference row and place the results in corresponding cells of sheet3.all these operations should be done at a time by clicking the button in sheet1.
    20 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following