Hi Alan,
thanks for the code but it doesn't do what I need to do.
I am trying to explain the full picture of my file:
1. I have a User form in sheet1 where I am adding new records.
2. When I save (or submit) the form all the data are added to Database sheet as a new line (this is working just fine with the bellow code)
3. At the same time as before (save or submit the form) I need that only the "Amount" value to be added to Database1 sheet in the corresponding cellCode:Sub Submit_Data() Dim sh As Worksheet Dim sh1 As Worksheet Dim iRow As Long, colno As Integer, iCol As Long, rowno As Integer Dim iRow1 As Long, colno1 As Integer, iCol1 As Integer, reqdRow As Integer Set sh = ThisWorkbook.Sheets("Database") Set sh1 = ThisWorkbook.Sheets("Database1") iRow = [Counta(Database!A:A)] + 1 iCol = Sheets("Database").Cells(1, Columns.Count).End(xlToLeft).Column - 1 iRow1 = [Counta(Database1!A:A)] + 1 iCol1 = Sheets("Database1").Cells(1, Columns.Count).End(xlToLeft).Column - 1 Application.ScreenUpdating = False With sh .Cells(iRow, 1) = iRow - 1 .Cells(iRow, 2) = UserFormTest.CmbYear.Value .Cells(iRow, 3) = UserFormTest.CmbMonth.Value .Cells(iRow, 4) = UserFormTest.CmbName.Value .Cells(iRow, 5) = UserFormTest.CmbProject.Value .Cells(iRow, 6) = UserFormTest.CmbTask.Value .Cells(iRow, 7) = UserFormTest.TxtAmount.Value .Cells(iRow, 8) = Application.UserName End With
Ex. the amount of 100 from Database sheet (first record) must be added to cell "D15" (with yellow in Database1 sheet) because that cell is the corresponding cell for "Year 2022" "Month January" "Name bbb" "Project2" "Task2"
The above code is matching the "Name" and "Project" but not the "Task" and this is where I need your help.Code:With sh1 For rowno = 2 To iRow1 If .Cells(rowno, 1) = UserFormTest.CmbName.Value And .Cells(rowno, 2) = UserFormTest.CmbProject.Value Then reqdRow = rowno Exit For End If Next For colno = 4 To iCol1 If UserFormTest.CmbMonth.Value = Format(.Cells(1, colno), "MMMM") And _ UserFormTest.CmbYear.Value = Format(.Cells(1, colno), "YYYY") Then .Cells(reqdRow, colno) = UserFormTest.TxtAmount.Value End If Next .Cells(iRow, iCol1 + 3) = Application.UserName End With Call Reset Application.ScreenUpdating = True MsgBox "Date incarcate cu succes!" End Sub
Thanks again!
Liviu




Reply With Quote
Bookmarks