Avatar billede al_pacone Nybegynder
03. maj 2004 - 01:35 Der er 4 kommentarer og
1 løsning

Find og tæl celler.

Jeg bruger følgende kode til at finde og tælle celler.
Problemet er at den finder første og anden dato, men glemmer at få lagt månedens længde til den anden dato den finder. C mangler at blive forlænget med en måned.


Public Sub FindNavne()

Dim A As Variant

For C = 3 To 65000
Sheets("Turnusplan").Select
  Cells(C, 2).Select
  If Cells(C, 2) = "" Then GoTo IkkeFlere
  M = Int(Month(Cells(C, 2)))
  Y = Int(Year(Cells(C, 2)))

If M = Range("Sm") And Y = Range("så") Then
    R1 = C
    K1 = 2
End If

If M = Range("SLM") And Y = Range("SLÅ") Then
    R2 = C
    K2 = 15
 
GoTo IkkeFlere
  End If
   


If M = 1 Or M = 3 Or M = 5 Or M = 7 Or M = 8 Or M = 10 Or M = 12 Then C = C + 30
If M = 4 Or M = 6 Or M = 9 Or M = 11 Then C = C + 29
If Y Mod 4 = 0 And M = 2 Then C = C + 28
If Y Mod 4 <> 0 And M = 2 Then C = C + 27

Next C

'*************************** Udvalgte **************************
IkkeFlere:

A = Sheets("Print , statistik , mødetider").Range("D9")

  If Range("F2") = A Then
Range(Cells(R1, 6), Cells(R2, 6)).Select
GoTo TÆL
End If
 
  If Range("G2") = A Then
Range(Cells(R1, 7), Cells(R2, 7)).Select
GoTo TÆL
End If
 
'****************************** tæl farver *******************

TÆL:

Dim dCount As Double
   
    dCount = 0
    Application.Volatile
    For Each rCell In Selection
    If rCell.Interior.ColorIndex = Sheets("Print , statistik , mødetider").Range("C14").Interior.ColorIndex Then
            dCount = dCount + 1
        End If
    Next rCell
    Sheets("Print , statistik , mødetider").Range("F14") = dCount
   
   
    dCount = 0
    Application.Volatile
    For Each rCell In Selection
    If rCell.Interior.ColorIndex = Sheets("Print , statistik , mødetider").Range("C22").Interior.ColorIndex Then
            dCount = dCount + 1
        End If
    Next rCell
    Sheets("Print , statistik , mødetider").Range("F22") = dCount
   
    'Sheets("Turnusplan").Select
    'Cells(C, 2).Select
    Sheets("Print , statistik , mødetider").Select
   
End Sub
Avatar billede kabbak Professor
04. maj 2004 - 22:29 #1
Public Sub FindNavne()

Dim A As Variant

For C = 3 To 65000
Sheets("Turnusplan").Select
  Cells(C, 2).Select
  If Cells(C, 2) = "" Then GoTo IkkeFlere
  M = Int(Month(Cells(C, 2)))
  Y = Int(Year(Cells(C, 2)))

If M = Range("Sm") And Y = Range("så") Then
    R1 = C
    K1 = 2
End If
   


If M = 1 Or M = 3 Or M = 5 Or M = 7 Or M = 8 Or M = 10 Or M = 12 Then C = C + 30
If M = 4 Or M = 6 Or M = 9 Or M = 11 Then C = C + 29
If Y Mod 4 = 0 And M = 2 Then C = C + 28
If Y Mod 4 <> 0 And M = 2 Then C = C + 27



If M = Range("SLM") And Y = Range("SLÅ") Then ' ER FLYTTET
    R2 = C
    K2 = 15
 
GoTo IkkeFlere
  End If


Next C

'*************************** Udvalgte **************************
IkkeFlere:

A = Sheets("Print , statistik , mødetider").Range("D9")

  If Range("F2") = A Then
Range(Cells(R1, 6), Cells(R2, 6)).Select
GoTo TÆL
End If
 
  If Range("G2") = A Then
Range(Cells(R1, 7), Cells(R2, 7)).Select
GoTo TÆL
End If
 
'****************************** tæl farver *******************

TÆL:

Dim dCount As Double
   
    dCount = 0
    Application.Volatile
    For Each rCell In Selection
    If rCell.Interior.ColorIndex = Sheets("Print , statistik , mødetider").Range("C14").Interior.ColorIndex Then
            dCount = dCount + 1
        End If
    Next rCell
    Sheets("Print , statistik , mødetider").Range("F14") = dCount
   
   
    dCount = 0
    Application.Volatile
    For Each rCell In Selection
    If rCell.Interior.ColorIndex = Sheets("Print , statistik , mødetider").Range("C22").Interior.ColorIndex Then
            dCount = dCount + 1
        End If
    Next rCell
    Sheets("Print , statistik , mødetider").Range("F22") = dCount
   
    'Sheets("Turnusplan").Select
    'Cells(C, 2).Select
    Sheets("Print , statistik , mødetider").Select
   
End Sub
Avatar billede al_pacone Nybegynder
05. maj 2004 - 01:00 #2
Så virker det også.
Tak for hjælpen.
Avatar billede kabbak Professor
05. maj 2004 - 16:46 #3
Var det, det der skulle til.

jeg kunne se, at når du nåede slutmåneden blev værdierne ikke lagt til, fordi den mødte "GoTo IkkeFlere" inden.

Og et svar.
Avatar billede kabbak Professor
15. juni 2004 - 22:55 #4
hallo ?
Avatar billede al_pacone Nybegynder
02. september 2004 - 04:59 #5
Har vist glemt at lukke.
Fik kun sagt tak.
Undskyld ventetiden.
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