Hi all, I'm using Excel 2003 and I'm writing a simple VBA application which inserts single credit card expenses into a sheet and then updates - in the same sheet but in a different area - the total on a month basis.
I have some problems in the month basis update because dates aren't managed correctly (but the code seems good, I can't find the error). Format I want to use for the month base total is "MMM-yy". 1) Input is inserted by a form where you put expense amount, some other details and date which is initialized to Now: //START FORM LOADING Private Sub LoadCreditCardForm_Click() CreditCardForm.DataTextBox = Format(Now(), "dd/MM/yyyy") ... CreditCardForm.Show End Sub //END FORM LOADING 2) After pressing the "Insert" button on the form, it inserts a new row in the sheet of Credit Card Expenses at the end of the populated rows. This works fine. //START Private Sub InsertButton_Click() Dim expDate As Date expDate = CDate(CreditCardForm.DataTextBox) For r = 2 To 10000 If Worksheets("Credit Card").Cells(r, 1).Value = "" Then ... Worksheets("Credit Card").Cells(r, 2).Value = Format (expDate , "MM/dd/yy") Worksheets("Credit Card").Cells(r, 3).Value = CDbl (CreditCardForm.AmountTextBox) ... Exit For End If Next //END 3) Then in the same code file it updates the total of the month, if exists, otherwise it creates a new row for the total of the month. The problem is that it doesn't ever find the total even if it exists and inserts a new row (with the same total month string but - incredible - it considers it as different) //START bFound = False 'look for correct row and update it if found For r = 2 To 10000 If Worksheets("Credit Card").Cells(r, 10).Value = Format (expDate , "MMM-yy") Then Worksheets("Credit Card").Cells(r, 11).Value = Worksheets("Carte Credito").Cells(r, 11) + CDbl (CreditCardForm.AmountTextBox) bFound = True Exit For End If Next 'if total isn't found it creates a new one at the end of the total area If Not bFound Then For r = 2 To 10000 If Worksheets("Credit Card").Cells(r, 9).Value = "" Then Worksheets("Carte Credito").Cells(r, 10).Value = Format(expDate , "MMM/yy") Worksheets("Carte Credito").Cells(r, 11).Value = CDbl(CreditCardForm.AmountTextBox) Exit For End If Next End If End Sub //END Thanks all for every suggestion and best regards, Ale --~--~---------~--~----~------------~-------~--~----~ ---------------------------------------------------------------------------------- Some important links for excel users: 1. Excel and VBA Tutorials(Video and Text), Free add-ins downloads at http://www.excelitems.com 2. Excel tutorials at http://www.excel-macros.blogspot.com 3. Learn VBA Macros at http://www.vbamacros.blogspot.com 4. Excel Tips and Tricks at http://exceldailytip.blogspot.com To post to this group, send email to excel-macros@googlegroups.com If you find any spam message in the group, please send an email to: Ayush Jain @ jainayus...@gmail.com or Ashish Jain @ 26may.1...@gmail.com <><><><><><><><><><><><><><><><><><><><><><> HELP US GROW !! We reach over 5,200 subscribers worldwide and receive many nice notes about the learning and support from the group. Our goal is to have 10,000 subscribers by the end of 2009. Let friends and co-workers know they can subscribe to group at http://groups.google.com/group/excel-macros/subscribe -~----------~----~----~----~------~----~------~--~---