Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default AfterUpdate Code to Subtract Column (L) from (G)

- Column L is the sold column.
- Column G is the Remaining Qty in Stock.
- When the value in L is typed in, I need the value in G (Qty in Stock) to
lower by that L value

I need this Code to run "after" the user types in the L value and hits
"Enter" or "Arrow Down"

I have tried this, but it does nothing at all?
-----------------------------------------------------------
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Address = "$L$2" Then
Range("G2") = Range("G2") - Range("L2")
End If

End Sub
----------------------------------------------------------
Thanks,
jlig

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default AfterUpdate Code to Subtract Column (L) from (G)

Thanks for the reply..
I tried the code..get Compile Error: Variable not defined?

I then tried adding in Dim isect = String but get Compile Error: Object
Required?

I'm using Excel 2007 and have Macros/VB code allowed..
Thanks..
jlig

Per Jessen wrote:
Hi

It should work if your code is placed in the code sheet for ThisWorkbook.
But only for changes in L2.

As I suppose you only want this function on one sheet, I suggest you use a
Worksheet_Change event, which is to be placed in the code sheet for the
desired worksheet.

The solution below work on changes in L2:L100:

Private Sub Worksheet_Change(ByVal Target As Range)
Set isect = Intersect(Target, Range("L2:L100"))
If Not isect Is Nothing Then
TargetRow = Target.Row
Range("G" & TargetRow) = Range("G" & TargetRow) - Range("L" & TargetRow)
End If
End Sub

Hopes this helps.

---
Per

- Column L is the sold column.
- Column G is the Remaining Qty in Stock.

[quoted text clipped - 16 lines]
Thanks,
jlig


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200906/1

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default AfterUpdate Code to Subtract Column (L) from (G)

As the result in isect can be either a range or 'Nothing', you have to use

Dim isect as Variant

Regards,
Per

"jlig via OfficeKB.com" <u52556@uwe skrev i meddelelsen
news:978e220bc52b1@uwe...
Thanks for the reply..
I tried the code..get Compile Error: Variable not defined?

I then tried adding in Dim isect = String but get Compile Error: Object
Required?

I'm using Excel 2007 and have Macros/VB code allowed..
Thanks..
jlig

Per Jessen wrote:
Hi

It should work if your code is placed in the code sheet for ThisWorkbook.
But only for changes in L2.

As I suppose you only want this function on one sheet, I suggest you use a
Worksheet_Change event, which is to be placed in the code sheet for the
desired worksheet.

The solution below work on changes in L2:L100:

Private Sub Worksheet_Change(ByVal Target As Range)
Set isect = Intersect(Target, Range("L2:L100"))
If Not isect Is Nothing Then
TargetRow = Target.Row
Range("G" & TargetRow) = Range("G" & TargetRow) - Range("L" &
TargetRow)
End If
End Sub

Hopes this helps.

---
Per

- Column L is the sold column.
- Column G is the Remaining Qty in Stock.

[quoted text clipped - 16 lines]
Thanks,
jlig


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200906/1


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default AfterUpdate Code to Subtract Column (L) from (G)

Almost, After I added in the Dim for TargetRow, it all works great!
Thanks so much..

Final code:
-----------------
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
Dim isect As Variant
Dim TargetRow As Variant
Set isect = Intersect(Target, Range("L2:L100"))
If Not isect Is Nothing Then
TargetRow = Target.Row
Range("G" & TargetRow) = Range("G" & TargetRow) - Range("L" & TargetRow)
End If
End Sub
---------------------







Per Jessen wrote:
As the result in isect can be either a range or 'Nothing', you have to use

Dim isect as Variant

Regards,
Per

Thanks for the reply..
I tried the code..get Compile Error: Variable not defined?

[quoted text clipped - 36 lines]
Thanks,
jlig


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200906/1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
subtract column right from column left in excel? Muffin[_2_] New Users to Excel 2 June 17th 09 02:55 PM
AfterUpdate Code to Subtract Column (L) from (G) Per Jessen Excel Programming 0 June 13th 09 08:08 AM
Subtract and multiply as a code ???????? Tdp Excel Discussion (Misc queries) 6 November 10th 08 03:35 PM
HOW DO YOU ADD & SUBTRACT IN ONE COLUMN Stephanie Excel Worksheet Functions 1 September 25th 05 11:38 PM
VBA CODE to Subtract two cells Kevin Baker[_2_] Excel Programming 12 May 5th 05 04:23 PM


All times are GMT +1. The time now is 04:03 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"