muhleebbin
Active Member
- Joined
- Sep 30, 2017
- Messages
- 252
- Office Version
- 365
- 2019
- 2016
- 2013
- 2010
- Platform
- Windows
- MacOS
- Mobile
- Web
I have the following code (thanks to the internet) in a spreadsheet that will slightly change in a new use. The code itself creates a new entry on a new line, is it possible to overwrite an existing entry on whichever line i'm currently viewing (there is other code that let's me go through the entries as they were entered). I would only need to be able to change one cell (G5) from the potential options of Approved, Pending Approval, Proposed.
Thank you in advance for your assistance!
Thank you in advance for your assistance!
VBA Code:
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
'cells to copy from Input sheet - some contain formulas
myCopy = "G3,G5,G7,F10,F11,F12,F13,F14,F15,F16,F18,F19,F20,F21,F22,F23,G10,G11,G12,G13,G14,G15,G16,G18,G19,G20,G21,G22,G23,H10,H11,H12,H13,H14,H15,H16,H18,H19,H20,H21,H22,H23"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("Data")
With historyWks
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 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
'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
Range("G3:I3").Select
Selection.ClearContents
Range("G5:I5").Select
Selection.ClearContents
Range("G7:I7").Select
Selection.ClearContents
Range("F10").Select
ActiveCell.FormulaR1C1 = "0"
Range("F11").Select
ActiveCell.FormulaR1C1 = "0"
Range("F12").Select
ActiveCell.FormulaR1C1 = "0"
Range("F13").Select
ActiveCell.FormulaR1C1 = "0"
Range("F14").Select
ActiveCell.FormulaR1C1 = "0"
Range("F15").Select
ActiveCell.FormulaR1C1 = "0"
Range("F16").Select
ActiveCell.FormulaR1C1 = "0"
Range("F18").Select
ActiveCell.FormulaR1C1 = "0"
Range("F19").Select
ActiveCell.FormulaR1C1 = "0"
Range("F20").Select
ActiveCell.FormulaR1C1 = "0"
Range("F21").Select
ActiveCell.FormulaR1C1 = "0"
Range("F22").Select
ActiveCell.FormulaR1C1 = "0"
Range("F23").Select
ActiveCell.FormulaR1C1 = "0"
Range("G10").Select
ActiveCell.FormulaR1C1 = "0"
Range("G11").Select
ActiveCell.FormulaR1C1 = "0"
Range("G12").Select
ActiveCell.FormulaR1C1 = "0"
Range("G13").Select
ActiveCell.FormulaR1C1 = "0"
Range("G14").Select
ActiveCell.FormulaR1C1 = "0"
Range("G15").Select
ActiveCell.FormulaR1C1 = "0"
Range("G16").Select
ActiveCell.FormulaR1C1 = "0"
Range("G18").Select
ActiveCell.FormulaR1C1 = "0"
Range("G19").Select
ActiveCell.FormulaR1C1 = "0"
Range("G20").Select
ActiveCell.FormulaR1C1 = "0"
Range("G21").Select
ActiveCell.FormulaR1C1 = "0"
Range("G22").Select
ActiveCell.FormulaR1C1 = "0"
Range("G23").Select
ActiveCell.FormulaR1C1 = "0"
Range("H10").Select
ActiveCell.FormulaR1C1 = "0"
Range("H11").Select
ActiveCell.FormulaR1C1 = "0"
Range("H12").Select
ActiveCell.FormulaR1C1 = "0"
Range("H13").Select
ActiveCell.FormulaR1C1 = "0"
Range("H14").Select
ActiveCell.FormulaR1C1 = "0"
Range("H15").Select
ActiveCell.FormulaR1C1 = "0"
Range("H16").Select
ActiveCell.FormulaR1C1 = "0"
Range("H18").Select
ActiveCell.FormulaR1C1 = "0"
Range("H19").Select
ActiveCell.FormulaR1C1 = "0"
Range("H20").Select
ActiveCell.FormulaR1C1 = "0"
Range("H21").Select
ActiveCell.FormulaR1C1 = "0"
Range("H22").Select
ActiveCell.FormulaR1C1 = "0"
Range("H23").Select
ActiveCell.FormulaR1C1 = "0"
Range("G3:I3").Select
End Sub