I have a code, I think i got it from this forum (modified a bit), but i can be wrong.
The code:
Private Sub CommandButton1_Click()
Dim DstRng As Range
Dim Rng As Range
Dim RngEnd As Range
Dim SrcRng As Range
Dim Response As VbMsgBoxResult
Response = MsgBox("Kas oled kindel, et soovid andmed arhiivi salvestada?" & vbCrLf & "(kaasneb väljade tühjendamine)", vbQuestion + vbYesNo Or vbDefaultButton2, "Andmete salvestamine")
If Response = vbYes Then
With Worksheets("Arhiiv")
Set Rng = .Range("A2")
Set RngEnd = .Cells(Rows.Count, Rng.Column).End(xlUp)
Set DstRng = IIf(RngEnd.Row < Rng.Row, Rng, RngEnd.Offset(2, 0))
End With
With Worksheets("Eri_fr")
Set Rng = .Range("soelkover")
Set SrcRng = Rng
End With
Set SrcRng = SrcRng.Resize(ColumnSize:=30)
DstRng.Cells(1, 1).Resize(SrcRng.Rows.Count, SrcRng.Columns.Count) = SrcRng.Value
MsgBox "Andmete salvestamine arhiivi oli edukas" & vbCrLf & "", vbInformation, "Andmete salvestamine"
Range("andmed").ClearContents
Range("A4:A5").ClearContents
Range("kaalud").ClearContents
CheckBox1.Value = False
End If
Range("A4").Select
Set wsArhiiv = Nothing
Set wsEri_fr = Nothing
Set rNextCl = Nothing
ThisWorkbook.Save
End Sub
I'm new to VBA. And i would be thankful.
Bookmarks