Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Macro Runs when the user changes any cell on the work sheet

I want to run a macro (just makes sure the end user doesn't accidentally
delete some of the formulas from a column) when the user adds/changes any
cell value. The idea is that they input the following on each line, and the
Total column multiplies the unit cost by the quantity.

Product Unit Cost £ Quantity Total


However, if they add rows the formula disappears and the calculation doesn't
work. I want to add a macro so when they add/change any of the left hand
cells (even if they have added a row) the formula will appear in the totals
column and complete the calculation.

Any ideas?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro Runs when the user changes any cell on the work sheet

Hello
Right-click on the worksheet tab, select View Code
With columns starting from A to D,
paste this sample code (with no exchaustive testing) and amend to your
needs:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Range("A:C")) _
Is Nothing Then
Dim r As Long
r = Target.Row
If Cells(r, "B").Value < "" And _
Cells(r, "C").Value < "" Then
Cells(r, "D").Value = Cells(r, "B") * Cells(r, "C")
End If
End If
End Sub

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news: ...
I want to run a macro (just makes sure the end user doesn't accidentally
delete some of the formulas from a column) when the user adds/changes any
cell value. The idea is that they input the following on each line, and
the
Total column multiplies the unit cost by the quantity.

Product Unit Cost £ Quantity Total


However, if they add rows the formula disappears and the calculation
doesn't
work. I want to add a macro so when they add/change any of the left hand
cells (even if they have added a row) the formula will appear in the
totals
column and complete the calculation.

Any ideas?



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Macro Runs when the user changes any cell on the work sheet

Hi
Thanks for the macro, I was wondering if there was a way of making it more
generic like if any row of column was changed the the calculation would be
done (the real data has a lot more columns and rows in reality).

Tom

"papou" wrote:

Hello
Right-click on the worksheet tab, select View Code
With columns starting from A to D,
paste this sample code (with no exchaustive testing) and amend to your
needs:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Range("A:C")) _
Is Nothing Then
Dim r As Long
r = Target.Row
If Cells(r, "B").Value < "" And _
Cells(r, "C").Value < "" Then
Cells(r, "D").Value = Cells(r, "B") * Cells(r, "C")
End If
End If
End Sub

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news: ...
I want to run a macro (just makes sure the end user doesn't accidentally
delete some of the formulas from a column) when the user adds/changes any
cell value. The idea is that they input the following on each line, and
the
Total column multiplies the unit cost by the quantity.

Product Unit Cost £ Quantity Total


However, if they add rows the formula disappears and the calculation
doesn't
work. I want to add a macro so when they add/change any of the left hand
cells (even if they have added a row) the formula will appear in the
totals
column and complete the calculation.

Any ideas?




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 112
Default Macro Runs when the user changes any cell on the work sheet

Tom
The sample code has no limits in rows, it just checks for the relevant
values in columns to achieve your calculation.
You can easily amend with the relevant range of columns (A to IV for
instance).
But you will need to identify both Unit Cost and Quantity columns (so it
can't be that generic).

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news: ...
Hi
Thanks for the macro, I was wondering if there was a way of making it more
generic like if any row of column was changed the the calculation would be
done (the real data has a lot more columns and rows in reality).

Tom

"papou" wrote:

Hello
Right-click on the worksheet tab, select View Code
With columns starting from A to D,
paste this sample code (with no exchaustive testing) and amend to your
needs:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Range("A:C")) _
Is Nothing Then
Dim r As Long
r = Target.Row
If Cells(r, "B").Value < "" And _
Cells(r, "C").Value < "" Then
Cells(r, "D").Value = Cells(r, "B") * Cells(r, "C")
End If
End If
End Sub

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news:
...
I want to run a macro (just makes sure the end user doesn't accidentally
delete some of the formulas from a column) when the user adds/changes
any
cell value. The idea is that they input the following on each line, and
the
Total column multiplies the unit cost by the quantity.

Product Unit Cost £ Quantity Total


However, if they add rows the formula disappears and the calculation
doesn't
work. I want to add a macro so when they add/change any of the left
hand
cells (even if they have added a row) the formula will appear in the
totals
column and complete the calculation.

Any ideas?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 47
Default Macro Runs when the user changes any cell on the work sheet

OK. I wasn't sure if I could just say something like if any column was change
(A:Z) then it would trigger the calculation.

Thanks.

"papou" wrote:

Tom
The sample code has no limits in rows, it just checks for the relevant
values in columns to achieve your calculation.
You can easily amend with the relevant range of columns (A to IV for
instance).
But you will need to identify both Unit Cost and Quantity columns (so it
can't be that generic).

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news: ...
Hi
Thanks for the macro, I was wondering if there was a way of making it more
generic like if any row of column was changed the the calculation would be
done (the real data has a lot more columns and rows in reality).

Tom

"papou" wrote:

Hello
Right-click on the worksheet tab, select View Code
With columns starting from A to D,
paste this sample code (with no exchaustive testing) and amend to your
needs:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range(Target.Address), Range("A:C")) _
Is Nothing Then
Dim r As Long
r = Target.Row
If Cells(r, "B").Value < "" And _
Cells(r, "C").Value < "" Then
Cells(r, "D").Value = Cells(r, "B") * Cells(r, "C")
End If
End If
End Sub

HTH
Cordially
Pascal

"raphiel2063" a écrit dans le
message de news:
...
I want to run a macro (just makes sure the end user doesn't accidentally
delete some of the formulas from a column) when the user adds/changes
any
cell value. The idea is that they input the following on each line, and
the
Total column multiplies the unit cost by the quantity.

Product Unit Cost £ Quantity Total


However, if they add rows the formula disappears and the calculation
doesn't
work. I want to add a macro so when they add/change any of the left
hand
cells (even if they have added a row) the formula will appear in the
totals
column and complete the calculation.

Any ideas?






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
Why macro runs on the same sheet? Harshad[_2_] Excel Discussion (Misc queries) 1 September 15th 08 09:39 AM
Cerfiticate Issues When User runs my Macro Jenny B. Excel Discussion (Misc queries) 0 January 18th 08 01:24 AM
Why is Sheet deleted when Macro runs... Darin Kramer Excel Programming 3 April 11th 06 02:50 PM
User to decide how often a macro runs Deedee Excel Discussion (Misc queries) 2 November 2nd 05 08:42 PM
Run macro but let user update spreadsheet while it runs Ev Excel Programming 5 September 9th 05 07:57 PM


All times are GMT +1. The time now is 05:20 PM.

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

About Us

"It's about Microsoft Excel"