View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.misc
JLatham JLatham is offline
external usenet poster
 
Posts: 3,365
Default Can anyone povide step by step instructions on how to do the f

Daniel,
Things are a little sparse as far as how and where your data is laid out
(what sheet(s) and what cells), but this will give you an idea of where to go
from here.

This assumes the following layout:
Everything is on the same worksheet
The budget table begins at A1 (the word "Expenses" is in A1)
and for this example,
your date selection is at H1
your category selection is at H2
and your amount entry is at H3

Then this code all goes into the worksheet's code section. To get to the
right place, right-click on the sheet's name tab and choose [View Code] from
the pop-up menu, then cut and paste this into that area in the VB Editor.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim theCategory As Long
Dim theDate As Long

If Application.Intersect(Target, Range("H3")) Is Nothing Then
Exit Sub
End If
If Range("H1") = "" Or Range("H2") = "" Then
Exit Sub ' can't match on no entry
End If
Application.EnableEvents = False
theCategory = Application.Match(Range("H2"), Rows("1:1"), 0)
theDate = Application.Match(Range("H1"), Columns("A:A"), 0)
ActiveSheet.Cells(theDate, theCategory) = Target.Value
'clean up entries for next entry
Range("H1:H3") = "" ' clear out entries made
Range("H1").Select ' ready for next entry
Application.EnableEvents = True
End Sub

To explain: the 1st 3 lines of code check that the change was to the amount
entry, and ignores any other changes made on the sheet.
The next 3 lines of code make sure our MATCH() statements will work, and if
they wouldn't (empty cell(s) at H1 or H2) then again, we just get out.

The .EnableEvents keeps the event from firing when we put the value on the
sheet so that we don't waste the extra time coming in and checking where that
happened and finding it wasn't in H3 and leaving again.

We 'steal' Excel's worksheet function MATCH() to find out the row number
that the date you chose was on in column A, and in which column of row 1 the
category appears in. MATCH() returns a number representing the position in
the searched list.
We then use the Cells() property of a worksheet to use those values from
MATCH() to tell it where to put the value you typed into H3 on the sheet.
Then the 3 input cells are cleared out and we go back up to H1, all ready for
another entry.

Before we leave, we turn .EnableEvents back on so that this will all happen
again when you make the next entry into cell H3.

Hope this helps get you going. Just change the various cell, row and/or
columns referenced in the code to match the way your sheet is really laid out
and it should be a good basis for getting it to work.

If you have got your data entry over in column A (as A1, A2, A3 instead of
H1, H2, H3) and your budget stuff actually starts in B1, then you'll need to
adjust the placing of the value into the matrix in the CELLS() reference.
Simply adjust that to account for the extra column offset as:
ActiveSheet.Cells(theDate, theCategory+1) = TargetValue

Also, if that's the kind of setup you have, then set up the lists so that
you are choosing the Date in A1, so that you won't get tripped up by always
having a MATCH() to your chosen category show up in column 1 when that
MATCH() is executed in the code across Row 1. Either that or bump your data
validated lists down to start below row 1.

"Daniel Bunt" wrote:



"JLatham" wrote:

There are a couple of approaches to take to easily solve this.

On the same sheet you could simply have 2 cells with Data Validation set up
to get the budget category entry and date from and another cell to enter the
amount into and a Worksheet_Change() event to detect when the budget amount
entry changes and go put the amount in the proper cell.

Another way, and this seems a little more like what I think you are looking
for, would be to set up a user form that would do much the same actions - 2
list boxes and an text entry box and a couple of command buttons should do it.

Third way would be to set up much like 1st way I described, but on a
separate sheet in the workbook.

If Excel's Help on topics such as Data Validation, the worksheet On Change
event and user forms don't get you the information you need, feel free to get
in touch with me at HelpFrom @ jlathamsite.com (remove spaces).


++++++++++++++++++++++++++++++++++++
Thankyou JLatham

Ive now learnt how to create a Data Validation List..

What i did was create 2 fields..
1st field.. Date Selection Validation List
2nd Feild.. Category Of Expense validation List

My only question at this point is...

How do i create a data entry box, then have it so the data entered will
use the validation selections to put the text into the right cell?

EG
Select Date: ( 03 Jan 07 )
Select Expense: (Entertainment)
Enter Amount : ( $25 ) Then press Enter

I want to type $25, hit enter, it saves, and it appears below on the correct
field, it then clears the box for another entry)

Expenses | Home & Garden | Entertainment | Food |
Date
01 jan 07
02 jan 07
03 Jan 07 $25
04 Jan 07
05 Jan 07


thankyou for your patience with this.