hamistasty
Board Regular
- Joined
- May 17, 2011
- Messages
- 208
I have code that on one page has a form and when the button is clicked the form contents is put into a table database in another sheet.
This code adds items fine. What I want to do is edit items that already exist in the database.
In cells G7 and G9 on the form, I want those cells to be a selection change update that compares G7 to column C or G9 to column G in sheet PartsData.
If it finds the corresponding number in column C or column G I want it to populate myCopy = "D5,D7,D9,D11,D13,D15,D17,D19,D21,D23" in my current code with that row of data in the database.
Any help?
This code adds items fine. What I want to do is edit items that already exist in the database.
In cells G7 and G9 on the form, I want those cells to be a selection change update that compares G7 to column C or G9 to column G in sheet PartsData.
If it finds the corresponding number in column C or column G I want it to populate myCopy = "D5,D7,D9,D11,D13,D15,D17,D19,D21,D23" in my current code with that row of data in the database.
Any help?
Code:
Option Explicit
Sub UpdateLogWorksheet()
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
myCopy = "D5,D7,D9,D11,D13,D15,D17,D19,D21,D23"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("PartsData")
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
oCol = oCol + 1
Next myCell
End With
With inputWks
On Error Resume Next
With .Range(myCopy).Cells.SpecialCells(xlCellTypeConstants)
.ClearContents
Application.GoTo .Cells(1)
End With
On Error GoTo 0
End With
End Sub