Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
Hi,
Sorry but this is probably a first grade question but I am so new to VBA that I am still working out how to type in code! All I want to do is ensure that when I have done the function I want that I am taken to the next available cell. Basically what I am trying to do (and probably the wrong way) is keep a record of entries in a field that constantly changes. When something else is changed it is updated but I want to keep a record of all the dates in that field. Please help |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
You may be able to adapt this to your needs. Say in Sheet1 we make manual
changes to cell A1. Every time we manually change A1 we want to record the new value and the date in Sheet2, in a running list. In the worksheet code area for Sheet1 enter: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("A1") Set s2 = Sheets("Sheet2") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Because it is worksheet code, it is very easy to install and automatic to use: 1. right-click the tab name near the bottom of the Excel window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you have any concerns, first try it on a trial worksheet. If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200779 "Leanne" wrote: Hi, Sorry but this is probably a first grade question but I am so new to VBA that I am still working out how to type in code! All I want to do is ensure that when I have done the function I want that I am taken to the next available cell. Basically what I am trying to do (and probably the wrong way) is keep a record of entries in a field that constantly changes. When something else is changed it is updated but I want to keep a record of all the dates in that field. Please help |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
Hi Gary,
Thanks, this sounds exactly what I want. I have given it a go and I have the following problems. 1. I have changed the Range to what I need (C2:C300) but it does not record changes to other cells. 2. It records a change when other cells are changed but records what is in C2 only and not the cell that was changed. I need to keep a record of changes to several cells and they may not all be changed at the same time. Also as each row is for a different customer I want to see the name of the customer whos information was changed. Thanks again "Gary''s Student" wrote: You may be able to adapt this to your needs. Say in Sheet1 we make manual changes to cell A1. Every time we manually change A1 we want to record the new value and the date in Sheet2, in a running list. In the worksheet code area for Sheet1 enter: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("A1") Set s2 = Sheets("Sheet2") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Because it is worksheet code, it is very easy to install and automatic to use: 1. right-click the tab name near the bottom of the Excel window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you have any concerns, first try it on a trial worksheet. If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200779 |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
We are making excellent progress!
Post the code as you have modified it and we will get it to work -- Gary''s Student - gsnu200779 "Leanne" wrote: Hi Gary, Thanks, this sounds exactly what I want. I have given it a go and I have the following problems. 1. I have changed the Range to what I need (C2:C300) but it does not record changes to other cells. 2. It records a change when other cells are changed but records what is in C2 only and not the cell that was changed. I need to keep a record of changes to several cells and they may not all be changed at the same time. Also as each row is for a different customer I want to see the name of the customer whos information was changed. Thanks again "Gary''s Student" wrote: You may be able to adapt this to your needs. Say in Sheet1 we make manual changes to cell A1. Every time we manually change A1 we want to record the new value and the date in Sheet2, in a running list. In the worksheet code area for Sheet1 enter: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("A1") Set s2 = Sheets("Sheet2") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Because it is worksheet code, it is very easy to install and automatic to use: 1. right-click the tab name near the bottom of the Excel window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you have any concerns, first try it on a trial worksheet. If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200779 |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
Private Sub Worksheet_Change(ByVal Target As Range)
Set t = Target Set ra = Range("C2:C300") Set s2 = Sheets("Visit History") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Thanks! On just about everything else Excel I have no trouble - just not VBA. "Gary''s Student" wrote: We are making excellent progress! Post the code as you have modified it and we will get it to work -- Gary''s Student - gsnu200779 "Leanne" wrote: Hi Gary, Thanks, this sounds exactly what I want. I have given it a go and I have the following problems. 1. I have changed the Range to what I need (C2:C300) but it does not record changes to other cells. 2. It records a change when other cells are changed but records what is in C2 only and not the cell that was changed. I need to keep a record of changes to several cells and they may not all be changed at the same time. Also as each row is for a different customer I want to see the name of the customer whos information was changed. Thanks again "Gary''s Student" wrote: You may be able to adapt this to your needs. Say in Sheet1 we make manual changes to cell A1. Every time we manually change A1 we want to record the new value and the date in Sheet2, in a running list. In the worksheet code area for Sheet1 enter: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("A1") Set s2 = Sheets("Sheet2") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Because it is worksheet code, it is very easy to install and automatic to use: 1. right-click the tab name near the bottom of the Excel window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you have any concerns, first try it on a trial worksheet. If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200779 |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
VBC Code
The only change you need to make in your version is to replace the line:
v = ra.Value with: v=t.Value Here is another version that goes a little further. Since we can change any of a set of cells and want to record the history, this version records that address of the cell being changed in column C of the "Visit History" worksheet. This we we know which cell has benn changed, the new value, and the date: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("C2:C300") Set s2 = Sheets("Visit History") If Intersect(ra, t) Is Nothing Then Exit Sub v = t.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date s2.Cells(n, 3).Value = t.Address Application.EnableEvents = True End Sub Of course, if you try the new version, you must delete the old version. -- Gary''s Student - gsnu200779 "Leanne" wrote: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("C2:C300") Set s2 = Sheets("Visit History") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Thanks! On just about everything else Excel I have no trouble - just not VBA. "Gary''s Student" wrote: We are making excellent progress! Post the code as you have modified it and we will get it to work -- Gary''s Student - gsnu200779 "Leanne" wrote: Hi Gary, Thanks, this sounds exactly what I want. I have given it a go and I have the following problems. 1. I have changed the Range to what I need (C2:C300) but it does not record changes to other cells. 2. It records a change when other cells are changed but records what is in C2 only and not the cell that was changed. I need to keep a record of changes to several cells and they may not all be changed at the same time. Also as each row is for a different customer I want to see the name of the customer whos information was changed. Thanks again "Gary''s Student" wrote: You may be able to adapt this to your needs. Say in Sheet1 we make manual changes to cell A1. Every time we manually change A1 we want to record the new value and the date in Sheet2, in a running list. In the worksheet code area for Sheet1 enter: Private Sub Worksheet_Change(ByVal Target As Range) Set t = Target Set ra = Range("A1") Set s2 = Sheets("Sheet2") If Intersect(ra, t) Is Nothing Then Exit Sub v = ra.Value n = s2.Cells(Rows.Count, 1).End(xlUp).Row + 1 Application.EnableEvents = False s2.Cells(n, 1).Value = v s2.Cells(n, 2).Value = Date Application.EnableEvents = True End Sub Because it is worksheet code, it is very easy to install and automatic to use: 1. right-click the tab name near the bottom of the Excel window 2. select View Code - this brings up a VBE window 3. paste the stuff in and close the VBE window If you have any concerns, first try it on a trial worksheet. If you save the workbook, the macro will be saved with it. To remove the macro: 1. bring up the VBE windows as above 2. clear the code out 3. close the VBE window To learn more about macros in general, see: http://www.mvps.org/dmcritchie/excel/getstarted.htm To learn more about Event Macros (worksheet code), see: http://www.mvps.org/dmcritchie/excel/event.htm -- Gary''s Student - gsnu200779 |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
split post code (zip code) out of cell that includes full address | Excel Discussion (Misc queries) | |||
Shorten code to apply to all sheets except a few, instead of individually naming them, and later adding to code. | Excel Programming | |||
Protect Sheet with code, but then code will not Paste error. How do i get around this. Please read for explainations.... | Excel Programming | |||
Excel code convert to Access code - Concat & eliminate duplicates | Excel Programming |