Hi Andrew,
Where should i put the codes in this vba?
Dim Err As Boolean
Sub SaveWbWithoutPrompt()
Dim path As String
Dim filename1 As String
Dim filename2 As String
Dim filename3 As String
Err = False
Check_Error_BeforeSave
If Err Then
Exit Sub
End If
unprotect
CopyValue
Sort1
locksheet
protect
path = "C:\Documents and Settings\Lenovo\Desktop\Dropbox\"
filename1 = Range("A1")
filename2 = Range("b4")
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:=path & filename1 & "-" & filename2 & "-" & Format(Date, "yyyy") & ".xls", FileFormat:=xlNormal
End Sub
Sub Check_Error_BeforeSave()
Dim msg As String
Dim Err2 As Boolean
Dim A As Integer
Err2 = False
If Worksheets("IDR").Range("b4").Value = "" Then
msg = msg & vbCrLf & "Periode tidak boleh kosong"
Err = True
End If
If Worksheets("USD").Range("b4").Value = "" Then
msg = msg & vbCrLf & "Periode tidak boleh kosong"
Err = True
End If
For A = 1 To 9999
If Range("A" & A + 5) <> "" And (Range("C" & A + 5)) = "" Then
Err2 = True
End If
Next A
If Err2 = True Then
msg = msg & vbCrLf & "KK/KM masih ada yang kosong"
Err = True
End If
For A = 1 To 9999
If Range("A" & A + 5) <> "" And (Range("d" & A + 5)) = "" Then
Err2 = True
End If
Next A
If Err2 = True Then
msg = msg & vbCrLf & "Jenis transaksi masih ada yang kosong"
Err = True
End If
For A = 1 To 9999
If Range("A" & A + 5) <> "" And (Range("f" & A + 5)) = "" Then
Err2 = True
End If
Next A
If Err2 = True Then
msg = msg & vbCrLf & "Keterangan masih ada yang kosong"
Err = True
End If
For A = 1 To 9999
If Range("C" & A + 5) = "KM" And Val(Range("g" & A + 5)) = 0 Then
Err2 = True
End If
Next A
If Err2 = True Then
msg = msg & vbCrLf & "Debit/ kredit ada yang tidak cocok"
Err = True
End If
For A = 1 To 9999
If Range("C" & A + 5) = "KK" And Val(Range("h" & A + 5)) = 0 Then
Err2 = True
End If
Next A
If Err2 = True Then
msg = msg & vbCrLf & "Debit/ kredit ada yang tidak cocok"
Err = True
End If
If Err Then
MsgBox msg
End If
End Sub
Sub Sort1()
Dim oneRange As Range
Dim aCell As Range
Set oneRange = Range("a5:i9994")
Set aCell = Range("a5")
oneRange.Sort Key1:=aCell, Order1:=xlAscending, Header:=xlYes
End Sub
Sub CopyValue()
Dim LastRow As Long
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With Range("A6:i" & LastRow)
.Value = .Value
End With
With Range("k6:M" & LastRow)
.Value = .Value
End With
End Sub
Sub locksheet()
Dim LastRow As Long
With ActiveSheet
LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
.Range("A6:i" & LastRow).Locked = True
.protect Password:="maghabo", AllowFiltering:=True
End With
End Sub
Sub unprotect()
ActiveSheet.unprotect Password:="maghabo"
End Sub
Sub protect()
ActiveSheet.protect Password:="maghabo", AllowFiltering:=True
End Sub