Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to trigger one cell change to change another cell using VB in excel? Please help! :)

I am currently embarking on a school project regarding excel and
visual basic within excel.

I have no prior knowledge to programming and my project is due very
soon so please help if you can! :)

Here's what I hope to achieve:

There are 2 columns of cells.

The value of the cells in the 2nd column will decrease given something
to trigger it.
What I hope is that the value by which the 2nd column decrease will be
added to the value in the 1st column's cells.

Does anyone know any way to do it and loop all the way downwards for
all active cells?
Please show me an example of the code and be as descriptive as you can
as I'll probably take hours to read and understand it.

Thanks a million! :)

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,173
Default How to trigger one cell change to change another cell using VB in excel? Please help! :)

Generally we don't help with assignments, but as you admit yours is, here's
a start

If your data is in say A1:B1000 you could do this (not the most elegant but
it works)

Sub SubtractBAddA()
Dim myCell As Range
For Each myCell In Range("A1:A1000")
myCell.Value = myCell.Value + 1
Next myCell
Set myCell = Nothing
For Each myCell In Range("B1:B1000")
myCell.Value = myCell.Value - 1
Next myCell
End Sub

To implement, decide how you trigger it and improve, well there's here,
websites, etc...over to you

--
HTH
Nick Hodge
Microsoft MVP - Excel
Southampton, England
DTHIS
www.nickhodge.co.uk


"raytan" wrote in message
ups.com...
I am currently embarking on a school project regarding excel and
visual basic within excel.

I have no prior knowledge to programming and my project is due very
soon so please help if you can! :)

Here's what I hope to achieve:

There are 2 columns of cells.

The value of the cells in the 2nd column will decrease given something
to trigger it.
What I hope is that the value by which the 2nd column decrease will be
added to the value in the 1st column's cells.

Does anyone know any way to do it and loop all the way downwards for
all active cells?
Please show me an example of the code and be as descriptive as you can
as I'll probably take hours to read and understand it.

Thanks a million! :)


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 163
Default How to trigger one cell change to change another cell using VB in excel? Please help! :)

Hi,

I am currently embarking on a school project
regarding excel and visual basic

I have no prior knowledge to programming


Which doesn't make things any easier.

I don't know whether what you want is possible at all.

This one deducts a random value from 1 to 10
from all cells in column 2,
and adds it to all cells in columns 1.

Public Sub Test80x()
Dim lngR As Long ' row
Dim lngX As Long ' just a value
Dim lngY As Long ' just a value
Randomize
lngX = CLng((9 * Rnd) + 1)
lngR = Cells(Rows.Count, 1).End(xlUp).Row
For lngY = 1 To lngR
Cells(lngY, 2).Value = Cells(lngY, 2).Value - lngX
Cells(lngY, 1).Value = Cells(lngY, 1).Value + lngX
Next
End Sub

See help for all and everything. Sorry. ;-)

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default How to trigger one cell change to change another cell using VB in excel? Please help! :)

Ideally this could be done if we had access to what triggers the cell
change. Since we apparently don't, we need to somehow get the original value
of column B before it was changed. Assuming the value change will trigger
the Worksheet_Change event, we could use that to capture the new value and
use the Application.Undo method to capture the original value. Then subtract
new value from original value and add the difference to column A. Finally,
assign column B back to the new value.

Mike F
"raytan" wrote in message
ups.com...
I am currently embarking on a school project regarding excel and
visual basic within excel.

I have no prior knowledge to programming and my project is due very
soon so please help if you can! :)

Here's what I hope to achieve:

There are 2 columns of cells.

The value of the cells in the 2nd column will decrease given something
to trigger it.
What I hope is that the value by which the 2nd column decrease will be
added to the value in the 1st column's cells.

Does anyone know any way to do it and loop all the way downwards for
all active cells?
Please show me an example of the code and be as descriptive as you can
as I'll probably take hours to read and understand it.

Thanks a million! :)



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How to trigger one cell change to change another cell using VB in excel? Please help! :)

Oh and I'm thinking how do I trigger it such that it autocalculates
whenever the value in cell 2 decreases? such that the cell 1 will
automatically go up? cos the value by which cell 2 decreases in
triggered by another worksheet in the same file..

thanks a lot!

On Mar 25, 5:11 pm, "raytan" wrote:
I am currently embarking on a school project regarding excel and
visual basic within excel.

I have no prior knowledge to programming and my project is due very
soon so please help if you can! :)

Here's what I hope to achieve:

There are 2 columns of cells.

The value of the cells in the 2nd column will decrease given something
to trigger it.
What I hope is that the value by which the 2nd column decrease will be
added to the value in the 1st column's cells.

Does anyone know any way to do it and loop all the way downwards for
all active cells?
Please show me an example of the code and be as descriptive as you can
as I'll probably take hours to read and understand it.

Thanks a million! :)



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
Trigger macro when specific cell doesn't change Gail Schweitzer Excel Programming 2 March 21st 07 07:28 PM
Trigger Macro on change in cell value qwerty[_2_] Excel Programming 3 April 26th 06 05:24 AM
Cell change to trigger Macro Sören_Marodören Excel Programming 2 April 11th 06 11:09 AM
Cell value change to trigger macro (worksheet change event?) Neil Goldwasser Excel Programming 4 January 10th 06 01:55 PM


All times are GMT +1. The time now is 10:12 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"