nithin shettigar
New Member
- Joined
- Mar 16, 2014
- Messages
- 44
I am getting debug error in (Set myRng = .Range(myCopy))
Sub UpdateLogWorksheet()
Dim warning As Integer
warning = MsgBox("Data Updated Cannot be Modified", vbYesNo + vbQuestion, "NOTE")
If warning = vbYes Then
Application.ScreenUpdating = False
Sheets("Database").Visible = True
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 = "N6,F7,F6,N5,N4,F5,J10,D29,D28,N7,Q7,R7,N29,N27,Q27,R27,H28,I28,J28,K28,S28,N28,Q28,R28,D27,D25,I25,N25,D22,E23,N22,Q22,R22,I23,N23,Q23,R23,D21,I21,N21,D18,V10,V12,J19,K19,S18,N18,Q18,R18,V25,V27,J17,K17,S17,N16,Q16,R16,D14,I14,J14,N14,Q14,R14,M10,V5,V7,J13,K13,S13,N13,Q13,R13,N11,D9"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("Database")
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 "Incomplete Data-Please fill in all the Entries!"
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
Else
'do nothing
End If
Sheets("Database").Visible = False
Application.ScreenUpdating = True
End Sub
Sub UpdateLogWorksheet()
Dim warning As Integer
warning = MsgBox("Data Updated Cannot be Modified", vbYesNo + vbQuestion, "NOTE")
If warning = vbYes Then
Application.ScreenUpdating = False
Sheets("Database").Visible = True
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 = "N6,F7,F6,N5,N4,F5,J10,D29,D28,N7,Q7,R7,N29,N27,Q27,R27,H28,I28,J28,K28,S28,N28,Q28,R28,D27,D25,I25,N25,D22,E23,N22,Q22,R22,I23,N23,Q23,R23,D21,I21,N21,D18,V10,V12,J19,K19,S18,N18,Q18,R18,V25,V27,J17,K17,S17,N16,Q16,R16,D14,I14,J14,N14,Q14,R14,M10,V5,V7,J13,K13,S13,N13,Q13,R13,N11,D9"
Set inputWks = Worksheets("Input")
Set historyWks = Worksheets("Database")
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 "Incomplete Data-Please fill in all the Entries!"
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
Else
'do nothing
End If
Sheets("Database").Visible = False
Application.ScreenUpdating = True
End Sub