17. oktober 2011 - 09:34
Der er
2 kommentarer og 1 løsning
Excel - Overfør data fra en workbooks userform til en anden workbook(database)!
Jeg har nogle problemer med at få overført data fra en userform i en workbook til et sheet i en anden workbook. Min kode ser sådan ud: Private Sub OFok_Click() Dim iRow As Long Dim ws As Worksheet Set ws = Worksheets("fejl1") 'find first empty row in database iRow = ws.Cells(Rows.Count, 1) _ .End(xlUp).Offset(1, 0).Row 'check for a part number If Trim(Me.OFb.Value) = "" Then Me.OFb.SetFocus MsgBox "Udfyld!" Exit Sub End If If Trim(Me.OFp.Value) = "" Then Me.OFp.SetFocus MsgBox "udfyld!" Exit Sub End If Application.ScreenUpdating = False Workbooks.Open Filename:=ThisWorkbook.Path & "\" & "database.xlsm" 'copy the data to the database ws.Cells(iRow, 1).Value = Me.OFna.Value ws.Cells(iRow, 2).Value = Me.OFbn.Value ws.Cells(iRow, 3).Value = Me.OFt.Value ws.Cells(iRow, 4).Value = Me.OFem.Value ws.Cells(iRow, 5).Value = Me.OFo.Value ws.Cells(iRow, 6).Value = Me.OFa.Value ws.Cells(iRow, 7).Value = Me.OFe.Value ws.Cells(iRow, 8).Value = Me.OFb.Value ws.Cells(iRow, 9).Value = Me.OFp.Value ws.Cells(iRow, 10).Value = Me.OFdato.Value ActiveWorkbook.Save ActiveWorkbook.Close Application.ScreenUpdating = True Unload Me End Sub Jeg har på fornemmelsen at det bare er en taste fejl et sted, men jeg kan ikke finde den. Med venlig hilsen Jesper Vejby
Annonceindlæg fra Computerworld it-jobbank
17. oktober 2011 - 10:15
#1
Du er velkommen til at sende filerne til mig - så er det lettere at "steppe" igennem koden og se, hvad der sker. @-adresse under min profil.
17. oktober 2011 - 10:24
#2
Mange tak :)
17. oktober 2011 - 11:37
#3
Const dbSti = "C:\Users\peter\Desktop\JesperVejby\DataBase" Private Sub OFok_Click() Dim iRow As Long Dim ws As Worksheet 'open database file Workbooks.Open Filename:=dbSti & "\" & "database.xlsm" If Trim(Me.OFp.Value) = "" Then Me.OFp.SetFocus MsgBox "Vælg en prioritering" Exit Sub End If Rem vælg fane efter prioritet If Me.OFp.ListIndex = 0 Then Set ws = Worksheets("prio1") Else Set ws = Worksheets("prio2") End If 'find first empty row in database iRow = ws.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row 'check for a part number If Trim(Me.OFb.Value) = "" Then Me.OFb.SetFocus MsgBox "Beskriv kort fejlmeldingen" Exit Sub End If Application.ScreenUpdating = False 'copy the data to the database ws.Cells(iRow, 1).Value = Me.OFna.Value ws.Cells(iRow, 2).Value = Me.OFbn.Value ws.Cells(iRow, 3).Value = Me.OFt.Value ws.Cells(iRow, 4).Value = Me.OFem.Value ws.Cells(iRow, 5).Value = Me.OFo.Value ws.Cells(iRow, 6).Value = Me.OFa.Value ws.Cells(iRow, 7).Value = Me.OFe.Value ws.Cells(iRow, 8).Value = Me.OFb.Value ws.Cells(iRow, 9).Value = Me.OFp.Value ws.Cells(iRow, 10).Value = Me.OFdato.Value ActiveWorkbook.Save ActiveWorkbook.Close Application.ScreenUpdating = True Unload Me End Sub Private Sub OFan_Click() Unload Me End Sub Private Sub OFro_Click() Unload Me Bruger.Show End Sub Private Sub UserForm_Initialize() Dim ws As Worksheet Set ws = Worksheets("Fejlmelding") With Me.OFp .AddItem ("Højt prioriteret") 'prio1 .AddItem ("lavt prioriteret") 'prio2 End With Me.OFna.Value = ws.Range("E13") Me.OFbn.Value = ws.Range("E14") Me.OFt.Value = ws.Range("E15") Me.OFem.Value = ws.Range("E16") Me.OFo.Value = ws.Range("E17") Me.OFa.Value = ws.Range("E18") Me.OFe.Value = ws.Range("E19") Me.OFdato.Value = Format(Date) End Sub
Kurser inden for grundlæggende programmering