erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 453
Current using excel 2016 home version.
I am looking for VBA that will update two separate worksheets (customers & cars) using 1 worksheet (input). I am new at this so I started by doing one worksheet. I found the code below and modified it and it works fine, but now I am struggling with two worksheets.
Is it doable?
I am looking for VBA that will update two separate worksheets (customers & cars) using 1 worksheet (input). I am new at this so I started by doing one worksheet. I found the code below and modified it and it works fine, but now I am struggling with two worksheets.
Is it doable?
Code:
Sub UpdateLogWorksheet()
Dim CustomersWks 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
myCopy = "C3,C5,C7,C9,C11,G3,G5,G7,G9,G11"
Set inputWks = Worksheets("Input")
Set CustomersWks = Worksheets("Customers")
With CustomersWks
nextRow = .Cells(.Rows.Count, "A").End(xlUp).Offset(1, 0).Row
End With
With inputWks
Set myRng = .Range(myCopy)
If Application.CountA(myRng) <> myRng.Cells.Count Then
MsgBox "Please fill in all the cells!"
Exit Sub
End If
End With
With CustomersWks
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
CustomersWks.Cells(nextRow, oCol).Value = myCell.Value
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