khamha
Không có việc gì khó...
- Tham gia
- 4/6/10
- Bài viết
- 662
- Được thích
- 846
- Nghề nghiệp
- CNVC Laos
nhờ các bạn sửa lại cho nó save một lúc vào 03 sheet là sheet "SL" , sheet "N_Ma" và sheet "D_Ni"
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 = "O8,M3,M4,E6,M6,E7,N7,B8,D9,D10,H9,H10,N9,N10,N21,F12,F13,N12,F14,N13,N14,F15,N15,F16,N16,F17,N17,F18,N18,F19,N19,F20,N20,A23,D25,J25,C26,J26,D27,J27,G28,N28,D29,D30,L30,D31,G32,G33,J31,L31,D34,H34,M34"
Set inputWks = Worksheets("Form")
Set historyWks = Worksheets("SL")
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 "KhamHa KeoTaVen: Please fill in all!"
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
End Sub
cảm ơn các bạn.
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 = "O8,M3,M4,E6,M6,E7,N7,B8,D9,D10,H9,H10,N9,N10,N21,F12,F13,N12,F14,N13,N14,F15,N15,F16,N16,F17,N17,F18,N18,F19,N19,F20,N20,A23,D25,J25,C26,J26,D27,J27,G28,N28,D29,D30,L30,D31,G32,G33,J31,L31,D34,H34,M34"
Set inputWks = Worksheets("Form")
Set historyWks = Worksheets("SL")
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 "KhamHa KeoTaVen: Please fill in all!"
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
End Sub
cảm ơn các bạn.