14. februar 2008 - 20:09
Der er
3 kommentarer og
1 løsning
Hvorfor vil denne kode ikke udskrive til Arket?
Dim antalRæk, optælTab(), antalSælgere
Sub Optælling()
Rem Housekeeping
antalRæk = findAntalRækker
ReDim optælTab(antalRæk, 8)
nulstilTabel
Ugedage
optælRækker
visOptælling
End Sub
Private Function findAntalRækker()
findAntalRækker = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row - 1
End Function
Private Sub Ugedage()
Dim i As Integer
For i = 3 To antalRæk
With Workbooks("outbound.xls").Worksheets("data")
Cells(i, "B") = WeekdayName(Weekday(Cells(i, "A")), False, 1)
End With
Next
End Sub
Private Sub nulstilTabel()
For ix = 0 To antalRæk - 1
optælTab(ix, 0) = "" 'sælger-init
optælTab(ix, 1) = 0 'antal skemaer behandlet
optælTab(ix, 2) = 0 'antal prod.
optælTab(ix, 3) = 0 'antal abonnementer/forsikringer
optælTab(ix, 4) = 0 'antal lån
optælTab(ix, 5) = 0 'antal tale
optælTab(ix, 6) = 0 'lån omsætning
optælTab(ix, 7) = 0 'Øvrige omsætning
optælTab(ix, 8) = 0 'Samlet omsætning
Next ix
End Sub
Private Sub optælRækker()
Dim sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt
For ræk = 3 To antalRæk
sælger = Cells(ræk, 4)
antalskema = Cells(ræk, 5)
antalprod = Cells(ræk, 6)
antalabn = Cells(ræk, 7)
antallån = Cells(ræk, 8)
antaltele = Cells(ræk, 9)
lånomsæt = Cells(ræk, 10)
øvrigomsæt = Cells(ræk, 11)
optælItabel sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt
Next ræk
End Sub
Private Sub optælItabel(sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt)
antalSælgere = 0
For ix = 0 To antalRæk - 2
If optælTab(ix, 0) = sælger Then
optælTab(ix, 1) = optælTab(ix, 1) + antalskema
optælTab(ix, 2) = optælTab(ix, 2) + antalprod
optælTab(ix, 3) = optælTab(ix, 3) + antalabn
optælTab(ix, 4) = optælTab(ix, 4) + antallån
optælTab(ix, 5) = optælTab(ix, 5) + antaltele
optælTab(ix, 6) = optælTab(ix, 6) + lånomsæt
optælTab(ix, 7) = optælTab(ix, 7) + øvrigomsæt
optælTab(ix, 8) = optælTab(ix, 6) + optælTab(ix, 7)
Exit Sub
Else
If optælTab(ix, 0) = "" Then
optælTab(ix, 1) = optælTab(ix, 1)
optælTab(ix, 2) = optælTab(ix, 2)
optælTab(ix, 3) = optælTab(ix, 3)
optælTab(ix, 4) = optælTab(ix, 4)
optælTab(ix, 5) = optælTab(ix, 5)
optælTab(ix, 6) = optælTab(ix, 6)
optælTab(ix, 7) = optælTab(ix, 7)
optælTab(ix, 8) = optælTab(ix, 6) + optælTab(ix, 7)
antalSælgere = antalSælgere + 1
Exit Sub
End If
End If
Next ix
End Sub
Private Sub visOptælling()
Dim rRæk
With Workbooks("outbound.xls").Worksheets("prøve")
rRæk = antalRæk + 2
For sælger = 0 To antalSælgere - 2
Cells(rRæk, 1) = optælTab(sælger, 0)
Cells(rRæk, 2) = optælTab(sælger, 1)
Cells(rRæk, 3) = optælTab(sælger, 2)
Cells(rRæk, 4) = optælTab(sælger, 3)
Cells(rRæk, 5) = optælTab(sælger, 4)
Cells(rRæk, 6) = optælTab(sælger, 5)
Cells(rRæk, 7) = optælTab(sælger, 6)
Cells(rRæk, 8) = optælTab(sælger, 7)
Cells(rRæk, 9) = optælTab(sælger, 8)
rRæk = rRæk + 1
Next sælger
End With
End Sub
14. februar 2008 - 21:42
#1
Rettet lidt til men virker stadig ikke....
Option Explicit
Dim antalRæk, optælTab(), antalSælgere, ix As Integer
Sub Optælling()
Rem Housekeeping
antalRæk = findAntalRækker
ReDim optælTab(antalRæk, 8)
nulstilTabel
Ugedage
optælRækker
visOptælling
End Sub
Private Function findAntalRækker()
findAntalRækker = Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row - 1
End Function
Private Sub Ugedage()
Dim i As Integer
For i = 3 To antalRæk
With Workbooks("outbound.xls").Worksheets("data")
Cells(i, "B") = WeekdayName(Weekday(Cells(i, "A")), False, 1)
End With
Next
End Sub
Private Sub nulstilTabel()
Dim ix As Integer
For ix = 0 To antalRæk - 1
optælTab(ix, 0) = "" 'sælger-init
optælTab(ix, 1) = 0 'antal skemaer behandlet
optælTab(ix, 2) = 0 'antal prod.
optælTab(ix, 3) = 0 'antal abonnementer/forsikringer
optælTab(ix, 4) = 0 'antal lån
optælTab(ix, 5) = 0 'antal teleabn
optælTab(ix, 6) = 0 'lån omsætning
optælTab(ix, 7) = 0 'Øvrige omsætning
optælTab(ix, 8) = 0 'Samlet omsætning
Next ix
End Sub
Private Sub optælRækker()
Dim sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt
Dim Ræk As Integer
For Ræk = 3 To antalRæk
sælger = Cells(Ræk, 4)
antalskema = Cells(Ræk, 5)
antalprod = Cells(Ræk, 6)
antalabn = Cells(Ræk, 7)
antallån = Cells(Ræk, 8)
antaltele = Cells(Ræk, 9)
lånomsæt = Cells(Ræk, 10)
øvrigomsæt = Cells(Ræk, 11)
optælItabel sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt
Next Ræk
End Sub
Private Sub optælItabel(sælger, antalskema, antalprod, antalabn, antallån, antaltele, lånomsæt, øvrigomsæt)
antalSælgere = 0
For ix = 0 To antalRæk - 2
If optælTab(ix, 0) = sælger Then
optælTab(ix, 1) = optælTab(ix, 1) + antalskema
optælTab(ix, 2) = optælTab(ix, 2) + antalprod
optælTab(ix, 3) = optælTab(ix, 3) + antalabn
optælTab(ix, 4) = optælTab(ix, 4) + antallån
optælTab(ix, 5) = optælTab(ix, 5) + antaltele
optælTab(ix, 6) = optælTab(ix, 6) + lånomsæt
optælTab(ix, 7) = optælTab(ix, 7) + øvrigomsæt
optælTab(ix, 8) = optælTab(ix, 6) + optælTab(ix, 7)
Exit Sub
Else
If optælTab(ix, 0) = "" Then
optælTab(ix, 1) = optælTab(ix, 1)
optælTab(ix, 2) = optælTab(ix, 2)
optælTab(ix, 3) = optælTab(ix, 3)
optælTab(ix, 4) = optælTab(ix, 4)
optælTab(ix, 5) = optælTab(ix, 5)
optælTab(ix, 6) = optælTab(ix, 6)
optælTab(ix, 7) = optælTab(ix, 7)
optælTab(ix, 8) = optælTab(ix, 6) + optælTab(ix, 7)
antalSælgere = antalSælgere + 1
Exit Sub
End If
End If
Next ix
End Sub
Sub prøve()
Debug.Print optælTab(1, 2)
End Sub
Sub visOptælling()
Dim rRæk, sælger
rRæk = 1
For sælger = 0 To antalSælgere - 2
With Workbooks("outbound.xls").Worksheets("prøve")
.Cells(rRæk, 1) = optælTab(sælger, 0)
.Cells(rRæk, 2) = optælTab(sælger, 1)
.Cells(rRæk, 3) = optælTab(sælger, 2)
.Cells(rRæk, 4) = optælTab(sælger, 3)
.Cells(rRæk, 5) = optælTab(sælger, 4)
.Cells(rRæk, 6) = optælTab(sælger, 5)
.Cells(rRæk, 7) = optælTab(sælger, 6)
.Cells(rRæk, 8) = optælTab(sælger, 7)
.Cells(rRæk, 9) = optælTab(sælger, 8)
End With
rRæk = rRæk + 1
Next sælger
End Sub