Hello everyone!
First and foremost, please keep in mind I'm a complete noob in excel programming, so don't get frustrated if I my doubts are a bit silly.
I'm trying to work around a problem that might seem easy, but I've really no idea what I'm doing wrong. This is what I want to achieve:
1. Keep record of the "sold amount" and the "money collected" just by introducing those values in two cells ("entry cells"), so that in another two cells ("output cells") there is a sum of every value ever introduced in the first two cells.
2. Change the column coordinates of the "output cells" accordingly to the month I have selected in a list, so that every month has a separate column with its "total record".
3. Change the row coordinates of the "output cells" accordingly to a Membership ID Number, also introduced manually in another cell.
I managed to work out the first objective, but I'm incapable of doing the last 2. What I tried to do is creating 3 variables: one for the row coordinate (z), one for the "sold amount" column coordinate (x) and another for the "money collected" column coordinate (y). Then, use a formula in two cells in a separate worksheet ("Random") that gives me the appropiate column coordinate and set the value of x and y to the value of this cells (I'm sure theres is a way to do this in-code, but as I said before, I'm a complete noob). These formulas are working, I'm getting the appropiate coordinates for the month I've selected, but, as far as I'm concerned, I'm facing either of these problems:
1. I'm not setting the variables' value correctly.
2. I'm not using the proper syntax to use these variable as coordinates.
3. I have no clue where I am, which is the most probable one.
As asked by jomili, I'm attaching the spreadsheet and explaining exactly what I want it to do:
1. In the "Entry" sheet, I select the month we're in (A7).
1. I introduce the ID Number (A2) and the product that member wants to buy (D2).
2. I introduce the quantity he wants (E2) or the money he wants to expend (F2).
3. Cells E3 and F3 show the quantity and its price. To this point, everything is done using excel formulas. Now comes what I want the VBA code to do.
4. The quantity and price shown in E3 and F3, add up to the total quantity the member has bought this month (column H of the "Database" sheet, for January) and to the total speding he has made this month (column T of the "Database" sheet, for January).
5. Whenever I change the month, the next introduced quantities and prices add up to the its appropiate column in the "Database" sheet.
Thank you in advance for any helpful comments!!Option Explicit Dim quantity As Long Dim price As Long Dim adding As Integer Dim z As Long Dim x As Integer Dim y As Integer z = ActiveWorkbook.Sheets("Entry").Range("A2").Value + 1 x = ActiveWorkbook.Sheets("Random").Range("B1").Value y = ActiveWorkbook.Sheets("Random").Range("B2").Value Private Sub Worksheet_Change(ByVal Target As Range) If Target.Address = "$F$2" Or Target.Address = "$E$2" Then adding = adding + 1 If adding > 1 Then Exit Sub End If quantity = quantity + Sheets("Entry").Range("E3").Value ActiveWorkbook.Sheets("Database").Cells(z, x).Value = quantity price = price + Sheets("Entry").Range("F3").Value ActiveWorkbook.Sheets("Database").Cells(z, y).Value = price End If End Sub Private Sub Worksheet_SelectionChange(ByVal Target As Range) quantity = 0 price = 0 adding = 0 If Target.Address = "$F$2" Or Target.Address = "$E$2" Then quantity = ActiveWorkbook.Sheets("Base").Cells(z, x).Value price = ActiveWorkbook.Sheets("Base").Cells(z, y).Value End If End Sub
Bookmarks