Hi there,
I have created a spreadsheet with three front-end forms, which are designed to transfer data across to three corresponding worksheets. This functionality works successfully, however i also require the user to be able to enter data using the worksheet if they wish.
The issue now, is that when data is entered directly into the worksheet, and then the user uses the form say for example, for the next row of data; it won't populate the next row, it will instead overwrite what the user typed in the worksheet.
Does anyone know of a way that the form will populate data in the row below the data that was entered in the worksheet, so as not to lose or overwrite any data?
The three macro button VBA's are as follows:
1.)
2.)
3.)
If anyone is able to help with my query it would be very much appreciated.
Many thanks,
Adam
I have created a spreadsheet with three front-end forms, which are designed to transfer data across to three corresponding worksheets. This functionality works successfully, however i also require the user to be able to enter data using the worksheet if they wish.
The issue now, is that when data is entered directly into the worksheet, and then the user uses the form say for example, for the next row of data; it won't populate the next row, it will instead overwrite what the user typed in the worksheet.
Does anyone know of a way that the form will populate data in the row below the data that was entered in the worksheet, so as not to lose or overwrite any data?
The three macro button VBA's are as follows:
1.)
Code:
Sub UpdateLeadWorksheet()
'cells to copy from Input sheet - some contain formulas
myCopy = "C7:C15,C18:C23,G7:G14,G16:G24,K7:K12,K14:K19"
Set inputWks = Worksheets("Lead Input Form")
Set historyWks = Worksheets("BASFLead")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
If oCol = 11 Then oCol = 14 Else oCol = oCol + 1
Next myCell
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
End Sub
2.)
Code:
Sub CustomerRecords()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As String
Dim myCell As Range
'cells to copy from Input sheet - some contain formulas
myCopy = "C7,C8,C9,C10,C11,C12,F7,F8,F9,F10,F11,F12,F13,F14,F15,I7,I8,I9,I10,I11,I12,I13,I14,I15,I16"
Set inputWks = Worksheets("CustomerRecords Input Form")
Set historyWks = Worksheets("BASFCustomerRecords")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
If oCol = 8 Then oCol = 13 Else oCol = oCol + 1
Next myCell
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
End Sub
3.)
Code:
Sub SalesRepActivity()
Dim historyWks As Worksheet
Dim inputWks As Worksheet
Dim nextRow As Long
Dim oCol As Long
Dim myRng As Range
Dim myCopy As String
Dim myCell As Range
'cells to copy from Input sheet - some contain formulas
myCopy = "C7,C8,C9,C10,C11,C14,C15,C16,C17,C18,C19,C20,C21"
Set inputWks = Worksheets("SalesRepActivity Input Form")
Set historyWks = Worksheets("BASFSalesRepActivityRecord")
With historyWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
End With
With historyWks
With .Cells(nextRow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(nextRow, "B").Value = Application.UserName
oCol = 3
For Each myCell In myRng.Cells
historyWks.Cells(nextRow, oCol).Value = myCell.Value
If oCol = 7 Then oCol = 10 Else oCol = oCol + 1
Next myCell
End With
'clear input cells that contain constants
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1) ', Scroll:=True
End With
On Error GoTo 0
End With
End Sub
If anyone is able to help with my query it would be very much appreciated.
Many thanks,
Adam
Last edited by a moderator: