Avatar billede madiedk Nybegynder
02. juni 2008 - 18:38 Der er 2 kommentarer og
1 løsning

langsomt at skrive til excelark fra vba array

hej

jeg har en userform som gør at der bliver skrevet en masse data til et array. når man så klikker på en knap så skrive vba koden alt det i arrayet til et excelark.
problemet er at når man trykker på knappen så er det ligesom excel fryser i ca et minut inden den skriver dataen til arket. men hvis jeg klikker igen så skriver den det med det samme. hvorfor er den langsom første gang men ikke efterfølgende?
Avatar billede supertekst Ekspert
02. juni 2008 - 23:09 #1
Kunne du ikke vise koden her - eller du er velkommen til at sende filen til: pb@supertekst-it.dk
Avatar billede madiedk Nybegynder
03. juni 2008 - 12:33 #2
jo her:


Public Sub OpretBilagIExcel()
' skriver indeholdet fra bilagsarrayet til excel's bilag ark.
   
'On Error Resume Next
Dim i As Integer
Dim j As Integer


Set BilagsData = New adodb.Recordset

    BilagsData.Open "SELECT BOGFPOST.PORTEFOELJE, BOGFPOST.BOGF_KTO, BOGFPOST.BLB_AFD, BOGFPOST.TRAN_SEQ, BOGFPOST.BILAG, BOGFPOST.VALOER_DATO, BOGFPOST.BOGF_DATO, BOGFPOST.REG_DATO, BOGFPOST.TEKST FROM INV.BOGFPOST BOGFPOST WHERE (BOGFPOST.VALOER_DATO={ts '" & idag & "'}) AND (BOGFPOST.TEKST like 'Kalk%')", invcon, adOpenStatic
   
   
    Worksheets("bilag").Select
    Cells.Select
    Selection.ClearContents
   
    i = 1
   
    j = 0
   
   
    Application.Calculation = xlManual
    Application.ScreenUpdating = False
   

 
    For e = 1 To bilagindex - 1
   
        For k = 0 To BilagsData.RecordCount - 1
                ' AFDELING(0) OG BELØB(2)
                If StrComp(bilag(i, 1), BilagsData.Fields(0), vbTextCompare) = 0 And StrComp(Format(bilag(i, 82), "0"), CStr(BilagsData.Fields(2)), vbTextCompare) = 0 Then
               
                    'bilagsnr
                    Cells(2 + j, 3).Value = BilagsData.Fields(4)
                    Exit For
               
                End If
                BilagsData.MoveNext
                   
        Next k
   
        Cells(1 + j, 3).Value = "Bilagsnr:"
           
        If BilagsData.BOF = True And BilagsData.EOF = True Then
        Else
            BilagsData.MoveFirst
        End If

       
        ' skyldige omkostninger vedr 08
        Cells(29 + j, 1).Value = "Skyldige omkostninger vedr. 08:"
        Cells(29 + j, 2).Value = Format(bilag(i, 80), "0")
        Cells(29 + j, 2).NumberFormat = "#,##0"
           
        ' allerede registerede omkostninger
        Cells(30 + j, 1).Value = "Allerede registerede omkostninger:"
        Cells(30 + j, 2).Value = Format(bilag(i, 81), "0")
        Cells(30 + j, 2).NumberFormat = "#,##0"
       
        ' skyldige omkostninger til registering
        Cells(32 + j, 1).Value = "Skyldige omkostninger til reg.:"
        Cells(32 + j, 2).Value = Format(bilag(i, 82), "0")
        Cells(32 + j, 2).NumberFormat = "#,##0"
       
        ' bogføringskonti og tekst
        Cells(34 + j, 1).Value = "Bogført på konti: +800 og -900"
        Cells(35 + j, 1).Value = "Tekst: " + tekst
       
        ' afdelingsnr
        Cells(1 + j, 1).Value = "Afdelingsnr:"
        Cells(1 + j, 2).Value = bilag(i, 1)
       
        ' kursningsdato
        Cells(2 + j, 1).Value = "Kursningsdato:"
        Cells(2 + j, 2).Value = CDate(bilag(i, 87))
       
        ' Dags dato
        Cells(3 + j, 1).Value = "Dags dato:"
        Cells(3 + j, 2).Value = CDate(bilag(i, 88))
       
        ' formueIDkk
        Cells(6 + j, 1).Value = "Formue i DKK"
        Cells(6 + j, 2).Value = Format(bilag(i, 84), "0")
        Cells(6 + j, 2).NumberFormat = "#,##0"
       
        ' formue                                            ' formuevaluta
        Cells(4 + j, 1).Value = "Formue i afdelingsvaluta " + "(" + bilag(i, 85) + ")"
        Cells(4 + j, 2).Value = Format(bilag(i, 83), "0")
        Cells(4 + j, 2).NumberFormat = "#,##0"
       
        ' valutakurs
        Cells(5 + j, 1).Value = "Valutakurs " + "(" + bilag(i, 85) + ")"
        Cells(5 + j, 2).Value = Format((bilag(i, 86)), "0")

       
        'omkostnings satser
        Cells(8 + j, 4).Value = "OmkostningsID og beregningskode"
        Cells(8 + j, 4).Font.FontStyle = "Fed"
        Cells(9 + j, 4).Value = bilag(i, 90)
        Cells(10 + j, 4).Value = bilag(i, 91)
        Cells(11 + j, 4).Value = bilag(i, 92)
        Cells(12 + j, 4).Value = bilag(i, 93)
        Cells(13 + j, 4).Value = bilag(i, 94)
        Cells(14 + j, 4).Value = bilag(i, 95)
        Cells(15 + j, 4).Value = bilag(i, 96)
        Cells(16 + j, 4).Value = bilag(i, 97)
        Cells(17 + j, 4).Value = bilag(i, 98)
        Cells(18 + j, 4).Value = bilag(i, 99)
        Cells(19 + j, 4).Value = bilag(i, 100)
        Cells(20 + j, 4).Value = bilag(i, 101)
        Cells(21 + j, 4).Value = bilag(i, 102)
        Cells(22 + j, 4).Value = bilag(i, 103)
        Cells(23 + j, 4).Value = bilag(i, 104)
        Cells(24 + j, 4).Value = bilag(i, 105)
        Cells(25 + j, 4).Value = bilag(i, 106)
        Cells(26 + j, 4).Value = bilag(i, 107)
        Cells(27 + j, 4).Value = bilag(i, 108)
        Cells(28 + j, 4).Value = bilag(i, 109)
       
       
        'omkostningart
        Cells(8 + j, 1).Value = "Omkostningsart"
        Cells(8 + j, 1).Font.FontStyle = "Fed"
        Cells(9 + j, 1).Value = bilag(i, 42)
        Cells(10 + j, 1).Value = bilag(i, 43)
        Cells(11 + j, 1).Value = bilag(i, 44)
        Cells(12 + j, 1).Value = bilag(i, 45)
        Cells(13 + j, 1).Value = bilag(i, 46)
        Cells(14 + j, 1).Value = bilag(i, 47)
        Cells(15 + j, 1).Value = bilag(i, 48)
        Cells(16 + j, 1).Value = bilag(i, 49)
        Cells(17 + j, 1).Value = bilag(i, 50)
        Cells(18 + j, 1).Value = bilag(i, 51)
        Cells(19 + j, 1).Value = bilag(i, 52)
        Cells(20 + j, 1).Value = bilag(i, 53)
        Cells(21 + j, 1).Value = bilag(i, 54)
        Cells(22 + j, 1).Value = bilag(i, 55)
        Cells(23 + j, 1).Value = bilag(i, 56)
        Cells(24 + j, 1).Value = bilag(i, 57)
        Cells(25 + j, 1).Value = bilag(i, 58)
        Cells(26 + j, 1).Value = bilag(i, 59)
        Cells(27 + j, 1).Value = bilag(i, 60)
        Cells(28 + j, 1).Value = bilag(i, 61)
       
        'omkostningbeløb
        Cells(8 + j, 2).Value = "Omkostningsbeløb"
        Cells(8 + j, 2).Font.FontStyle = "Fed"
        Cells(8 + j, 2).HorizontalAlignment = xlRight
        Cells(9 + j, 2).Value = Format(bilag(i, 2), "0")
        Cells(9 + j, 2).NumberFormat = "#,##0"
        Cells(10 + j, 2).Value = Format(bilag(i, 3), "0")
        Cells(10 + j, 2).NumberFormat = "#,##0"
        Cells(11 + j, 2).Value = Format(bilag(i, 4), "0")
        Cells(11 + j, 2).NumberFormat = "#,##0"
        Cells(12 + j, 2).Value = Format(bilag(i, 5), "0")
        Cells(12 + j, 2).NumberFormat = "#,##0"
        Cells(13 + j, 2).Value = Format(bilag(i, 6), "0")
        Cells(13 + j, 2).NumberFormat = "#,##0"
        Cells(14 + j, 2).Value = Format(bilag(i, 7), "0")
        Cells(14 + j, 2).NumberFormat = "#,##0"
        Cells(15 + j, 2).Value = Format(bilag(i, 8), "0")
        Cells(15 + j, 2).NumberFormat = "#,##0"
        Cells(16 + j, 2).Value = Format(bilag(i, 9), "0")
        Cells(16 + j, 2).NumberFormat = "#,##0"
        Cells(17 + j, 2).Value = Format(bilag(i, 10), "0")
        Cells(17 + j, 2).NumberFormat = "#,##0"
        Cells(18 + j, 2).Value = Format(bilag(i, 11), "0")
        Cells(18 + j, 2).NumberFormat = "#,##0"
        Cells(19 + j, 2).Value = Format(bilag(i, 12), "0")
        Cells(19 + j, 2).NumberFormat = "#,##0"
        Cells(20 + j, 2).Value = Format(bilag(i, 13), "0")
        Cells(20 + j, 2).NumberFormat = "#,##0"
        Cells(21 + j, 2).Value = Format(bilag(i, 14), "0")
        Cells(21 + j, 2).NumberFormat = "#,##0"
        Cells(22 + j, 2).Value = Format(bilag(i, 15), "0")
        Cells(22 + j, 2).NumberFormat = "#,##0"
        Cells(23 + j, 2).Value = Format(bilag(i, 16), "0")
        Cells(23 + j, 2).NumberFormat = "#,##0"
        Cells(24 + j, 2).Value = Format(bilag(i, 17), "0")
        Cells(24 + j, 2).NumberFormat = "#,##0"
        Cells(25 + j, 2).Value = Format(bilag(i, 18), "0")
        Cells(25 + j, 2).NumberFormat = "#,##0"
        Cells(26 + j, 2).Value = Format(bilag(i, 19), "0")
        Cells(26 + j, 2).NumberFormat = "#,##0"
        Cells(27 + j, 2).Value = Format(bilag(i, 20), "0")
        Cells(27 + j, 2).NumberFormat = "#,##0"
        Cells(28 + j, 2).Value = Format(bilag(i, 21), "0")
        Cells(28 + j, 2).NumberFormat = "#,##0"
       
        'startdato
        Cells(8 + j, 3).Value = "Startdato"
        Cells(8 + j, 3).HorizontalAlignment = xlRight
        Cells(8 + j, 3).Font.FontStyle = "Fed"
        Cells(9 + j, 3).Value = bilag(i, 22)
        Cells(9 + j, 3).HorizontalAlignment = xlRight
        Cells(9 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(10 + j, 3).Value = bilag(i, 23)
        Cells(10 + j, 3).HorizontalAlignment = xlRight
        Cells(10 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(11 + j, 3).Value = bilag(i, 24)
        Cells(11 + j, 3).HorizontalAlignment = xlRight
        Cells(11 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(12 + j, 3).Value = bilag(i, 25)
        Cells(12 + j, 3).HorizontalAlignment = xlRight
        Cells(12 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(13 + j, 3).Value = bilag(i, 26)
        Cells(13 + j, 3).HorizontalAlignment = xlRight
        Cells(13 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(14 + j, 3).Value = bilag(i, 27)
        Cells(14 + j, 3).HorizontalAlignment = xlRight
        Cells(14 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(15 + j, 3).Value = bilag(i, 28)
        Cells(15 + j, 3).HorizontalAlignment = xlRight
        Cells(15 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(16 + j, 3).Value = bilag(i, 29)
        Cells(16 + j, 3).HorizontalAlignment = xlRight
        Cells(16 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(17 + j, 3).Value = bilag(i, 30)
        Cells(17 + j, 3).HorizontalAlignment = xlRight
        Cells(17 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(18 + j, 3).Value = bilag(i, 31)
        Cells(18 + j, 3).HorizontalAlignment = xlRight
        Cells(18 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(19 + j, 3).Value = bilag(i, 32)
        Cells(19 + j, 3).HorizontalAlignment = xlRight
        Cells(19 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(20 + j, 3).Value = bilag(i, 33)
        Cells(20 + j, 3).HorizontalAlignment = xlRight
        Cells(20 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(21 + j, 3).Value = bilag(i, 34)
        Cells(21 + j, 3).HorizontalAlignment = xlRight
        Cells(21 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(22 + j, 3).Value = bilag(i, 35)
        Cells(22 + j, 3).HorizontalAlignment = xlRight
        Cells(22 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(23 + j, 3).Value = bilag(i, 36)
        Cells(23 + j, 3).HorizontalAlignment = xlRight
        Cells(23 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(24 + j, 3).Value = bilag(i, 37)
        Cells(24 + j, 3).HorizontalAlignment = xlRight
        Cells(24 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(25 + j, 3).Value = bilag(i, 38)
        Cells(25 + j, 3).HorizontalAlignment = xlRight
        Cells(25 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(26 + j, 3).Value = bilag(i, 39)
        Cells(26 + j, 3).HorizontalAlignment = xlRight
        Cells(26 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(27 + j, 3).Value = bilag(i, 40)
        Cells(27 + j, 3).HorizontalAlignment = xlRight
        Cells(27 + j, 3).NumberFormat = "mm/dd/yyyy"
        Cells(28 + j, 3).Value = bilag(i, 41)
        Cells(28 + j, 3).HorizontalAlignment = xlRight
        Cells(28 + j, 3).NumberFormat = "mm/dd/yyyy"

        i = i + 1
        j = j + 36
   
    Next e
   
    Application.Calculation = xlCalculationAutomatic
    Application.ScreenUpdating = True

End Sub
Avatar billede madiedk Nybegynder
09. august 2008 - 13:26 #3
jeg lukker den så
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Excel kurser for alle niveauer og behov – find det kursus, der passer til dig

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester