hotpants49
New Member
- Joined
- May 29, 2011
- Messages
- 10
I am looking for some help with VB coding for an 'Update' button that saves information from one sheet (where users enter the data into specific cells) to a database sheet which will be hidden from user view so they don't break it. I would also like it to retrieve data from this database sheet whenever someone changes the date or shift number so they can see that it has already been entered and do not attempt to make a duplicate entry.
The spreadsheet I am working on is designed to track the denomination of currency we take through our 5 tills e.g. $100, $50, $20 etc. Each till is counted 3 times per day (we call these shifts). I have previously made a spreadsheet for keeping track of our total sales for each day using a userform.
I tried copying the VB code from that spreadsheet over to this sheet but I am unable to get it to work using two criteria for finding the correct row (all the rows in the database tab have the date in column A and the shift number in column B). It works fine just finding the date, but as I said we need it to record 3 shifts per day.
I also tried using a sort of ID number instead of date and shift number. I combined the date & shift number together in the same cell so 28/5/11 Shift 1 becomes 406911 but i couldn't get it to work.
Here is the code for the 'Update' button which saves the information to the database on another sheet, where:
"Data" is the sheet where I want to store the data.
"Key" is the named range of the ID number (date & shift number combined).
"Storage" is the named range inside the "Data" sheet where I want it stored, with the first column in the range being the ID number.
"Hundred" is the named range for the $100 currency cell.
The error I am getting is "Object variable or with block variable not set" when it gets to the irow = range("Stor.... etc.
Either way is fine (using a two column date & shift number system, or using a single column id number).
If it is easier without named ranges then:
"Key" = worksheets("Data Entry").range("V2")
"Hundred" = worksheets("Data Entry").range("Q9")
Storage I would like to keep as a named range if possible as I will be extending the sheet downwards when we have used all the days/shifts in it currently
Thankyou for your time
The spreadsheet I am working on is designed to track the denomination of currency we take through our 5 tills e.g. $100, $50, $20 etc. Each till is counted 3 times per day (we call these shifts). I have previously made a spreadsheet for keeping track of our total sales for each day using a userform.
I tried copying the VB code from that spreadsheet over to this sheet but I am unable to get it to work using two criteria for finding the correct row (all the rows in the database tab have the date in column A and the shift number in column B). It works fine just finding the date, but as I said we need it to record 3 shifts per day.
I also tried using a sort of ID number instead of date and shift number. I combined the date & shift number together in the same cell so 28/5/11 Shift 1 becomes 406911 but i couldn't get it to work.
Here is the code for the 'Update' button which saves the information to the database on another sheet, where:
"Data" is the sheet where I want to store the data.
"Key" is the named range of the ID number (date & shift number combined).
"Storage" is the named range inside the "Data" sheet where I want it stored, with the first column in the range being the ID number.
"Hundred" is the named range for the $100 currency cell.
The error I am getting is "Object variable or with block variable not set" when it gets to the irow = range("Stor.... etc.
Code:
Dim iRow As Long
Dim ws As Worksheet
Dim test1 As Long
Set ws = Worksheets("Data")
test1 = Range("Key")
iRow = Range("Storage").Find(What:=test1, LookIn:=xlFormulas _
, LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False).Row
'copy the data to the database
ws.Cells(iRow, 4).Value = Range("hundred")
If it is easier without named ranges then:
"Key" = worksheets("Data Entry").range("V2")
"Hundred" = worksheets("Data Entry").range("Q9")
Storage I would like to keep as a named range if possible as I will be extending the sheet downwards when we have used all the days/shifts in it currently
Thankyou for your time