02. februar 2006 - 14:56Der er
6 kommentarer og 1 løsning
For løkke med kørsler pr. kolonnelængde
Jeg har en for løkke: For i = 2 To 200
I stedet for 200 vil jeg gerne køre løkken det antal gange, som der er udfyldte felter i kolonne A fra A2. Der er ingen mellemrum mellem felterne i A, så man kan godt bruge Selection.End(xlDown)
Jeg skulle nok have sendt hele koden. Løkken stikker af på et tidspunkt, hvis man bruger din sætning i stedet for 200.
Sub start() For Each sh In ActiveWorkbook.Sheets shnavn = LCase(sh.Name)
If InStr("missing uam agentdeleted servers - all locations", shnavn) = 0 Then ActiveWorkbook.Sheets(shnavn).Activate For i = 2 To 200 Set curCell = ActiveSheet.Cells(i, 12) If (curCell.Value = "") Then ActiveSheet.Cells(i, 2).Select With Selection.Interior .ColorIndex = 7 .Pattern = xlSolid End With End If Next End If If InStr("missing uam agentdeleted servers - all locations", shnavn) = 0 Then ActiveWorkbook.Sheets(shnavn).Activate For i = 2 To 200 Set curCell = ActiveSheet.Cells(i, 37) If (curCell.Value = "") Then ActiveSheet.Cells(i, 2).Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid End With End If Next End If Next End Sub
Sub start() Dim sh As Worksheet Dim i As Long Dim shnavn As String Dim CurCell As Range
For Each sh In ActiveWorkbook.Sheets shnavn = LCase(sh.Name)
If InStr("missing uam agentdeleted servers - all locations", shnavn) = 0 Then For i = 2 To sh.Range("A2").End(xlDown).Row Set CurCell = sh.Cells(i, 12) If (CurCell.Value = "") Then With sh.Cells(i, 2).Interior .ColorIndex = 7 .Pattern = xlSolid End With End If Next End If If InStr("missing uam agentdeleted servers - all locations", shnavn) = 0 Then For i = 2 To sh.Range("A2").End(xlDown).Row Set CurCell = sh.Cells(i, 37) If (CurCell.Value = "") Then With sh.Cells(i, 2).Interior .ColorIndex = 8 .Pattern = xlSolid End With End If Next End If Next End Sub
Sub start() Dim sh As Worksheet Dim i As Long Dim shnavn As String Dim CurCell1 As Range Dim CurCell2 As Range For Each sh In ActiveWorkbook.Sheets shnavn = LCase(sh.Name) If InStr("missing uam agentdeleted servers - all locations", shnavn) = 0 Then For i = 2 To sh.Range("A2").End(xlDown).Row Set CurCell1 = sh.Cells(i, 12) Set CurCell2 = sh.Cells(i, 37) If (CurCell1.Value = "") Then sh.Cells(i, 2).Interior.ColorIndex = 7 If (CurCell2.Value = "") Then sh.Cells(i, 2).Interior.ColorIndex = 8 Next End If Next End Sub
Sub start() Dim wsh As Worksheet Dim rngCell As Range For Each wsh In ActiveWorkbook.Worksheets If InStr("missing uam agentdeleted servers - all locations", LCase(wsh.Name)) = 0 Then For Each rngCell In wsh.Range("A2:A" & wsh.Range("A2").End(xlDown).Row) If rngCell(1, 12).Value = "" Then rngCell(1, 2).Interior.ColorIndex = 7 If rngCell(1, 37).Value = "" Then rngCell(1, 2).Interior.ColorIndex = 8 Next End If Next End Sub
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.