Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 14th, 2007, 03:35 PM
Authorized User
 
Join Date: Jul 2007
Location: , , .
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default Compute Balance

How could I compute the balance from my column P(Debit) and Column Q(Credit) into column R(Balance).
I want use vba to do that (=P1-q1). If no data then just empty space. I have 1000 rows in that sheet.

I have 2 columns of data and 3rd column is a balance column.
And also want to lock the Balance column.


Data is like below

Debit Credit Balance(Result)
120 120 0
10 12 -2
        12 -12
30 30

.. ;; ;;
;; ;; ;;
Thanks in advance.....
Reply With Quote
  #2 (permalink)  
Old August 17th, 2007, 09:01 AM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Formula for C assuming your data starts in row 2 after headings:
=B2-A2
Populate this formula down.

To lock just B when the worksheet is locked:
1) Select all cells by clicking the button to the left of column A (Above row 1).
2) Click Format > Cells.
3) Click Protection Tab in the Format Cells menu.
4) Uncheck Locked.
5) Click OK.
6) Click C column button to select column C.
7) Click Format > Cells.
8) Click Protection Tab in the Format Cells menu if not already selected.
9) CHECK Locked.
10) Click OK.
11) Click Tools > Protection > Protect Sheet.
12) Make any additional permission choices.
13) Click OK.

Hope this helped point you in the right direction, but it really isn't a VBA question.


Reply With Quote
  #3 (permalink)  
Old August 17th, 2007, 09:16 AM
Friend of Wrox
Points: 513, Level: 8
Points: 513, Level: 8 Points: 513, Level: 8 Points: 513, Level: 8
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2007
Location: Davenport, IA, USA.
Posts: 163
Thanks: 0
Thanked 2 Times in 2 Posts
Default

Not sure why you WANT to use VBA... but you can make the code something like this:

------------------------------------------------------------------------
Private Sub CommandButton1_Click()

  Dim oSheets As Worksheet
  Set oSheets = Worksheets("Sheet1")
  oSheets.Range("C2:C5").Value = "=IF(AND(A2="""",B2=""""),"""",A2-B2)" 'Whatever range you want to set.
  oSheets.Cells.Locked = False
  oSheets.Range("C:C").Locked = True
  oSheets.Protect

End Sub
------------------------------------------------------------------------

The above sample does it when a button is clicked.

Also the formula above would be:
=IF(AND(A2="",B2=""),"",A2-B2)
instead of just =A2-B2 since you want "" when there is no values in A or B.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference between GROUP BY and COMPUTE BY rhd110 SQL Server 2005 1 April 28th, 2008 03:31 AM
Compute sum(column name) statement in DTS Package praragon SQL Server DTS 1 March 27th, 2006 10:23 PM
Roll Up\Cube\Compute aggregate funct. in Access? donnie200 Access VBA 7 January 25th, 2005 06:23 PM
DB CR Balance in Form mateenmohd Access 4 October 12th, 2004 11:32 PM
Which is Best For Balance tables alyeng2000 SQL Server 2000 1 March 9th, 2004 09:28 AM



All times are GMT -4. The time now is 04:07 AM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.