VBA - Colorindex i macro - Target.Row
HejJeg har nedeståedende kode, som kopier rækker fra Sheet1 til Sheet2.
Jeg vil gerne at farverne ændres, når der er blevet kopieret.
Macroen kopier hele rækken med, men efter kopiering af rækken, skal det kun værre en del af rækken, som skal farvelægges:
Fra Column A til Coloumn I.
Jeg havde tænkt mig noget med
"Range("A" & Target.Row & ":I" & Target.Row).Interior.ColorIndex = 15"
Linien skal flettes ind nederst i denne kode:
_---------------------------------------------------------
Sub Tilbud()
Dim i As Integer
Dim startCell As Integer
startCell = 10
Dim currentSheet As String
currentSheet = ActiveSheet.Name
Dim searchString As String
searchString = "Konsulenttimer dækker:"
If (currentSheet = "Indkøbsordre til OPI") Then
startCell = 18
searchString = "Vedr. kunde:"
End If
If (currentSheet = "Ordrebekræftelse (kunde)") Then
searchString = "Konsulenttimer dækker:"
End If
Dim celleId As Integer
celleId = 0
For i = 1 To 100
If Worksheets(currentSheet).Cells(i, 1).Value = searchString Then
celleId = i
End If
Next
If celleId <> 0 Then
For i = startCell To (celleId - 2)
Rows(startCell).Select
Selection.Delete Shift:=xlUp
Next
End If
Dim startVare, antalVare, startService, antalService As Integer
startVare = 4
antalVare = 31 '27
startService = startVare + antalVare + 4 '5
antalService = 13 '17
i = 0
'Insert headline row 2
Rows(startCell + i).Select
Selection.Insert Shift:=xlDown
For s = 1 To 9
Worksheets(currentSheet).Cells(startCell + i, s) = _
Worksheets("Prisberegning").Cells(2, s)
Next
Sheets("Prisberegning").Select
Rows("2:2").Select
Selection.Copy
Sheets(currentSheet).Select
Rows(startCell + i).Select
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 14
i = i + 1
For t = startVare To (antalVare + startVare)
If Worksheets("Prisberegning").Cells(t, 4).Value <> 0 Then
Worksheets(currentSheet).Rows(startCell + i).Select
Selection.Insert Shift:=xlDown
For s = 1 To 9
Worksheets(currentSheet).Cells(startCell + i, s) = _
Worksheets("Prisberegning").Cells(t, s)
Next
Rows(startCell + i).Select
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 14
Selection.Font.Bold = False
Cells(startCell + i, 1).Select
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
Cells(startCell + i, 4).Select
Selection.HorizontalAlignment = xlCenter
Cells(startCell + i, 5).Select
Selection.NumberFormat = "#,##0.00"
Cells(startCell + i, 6).Select
Selection.NumberFormat = "#,##0.00"
Cells(startCell + i, 7).Select
Selection.Style = "Percent"
Cells(startCell + i, 8).Select
Selection.NumberFormat = "#,##0.00"
Cells(startCell + i, 9).Select
Selection.NumberFormat = "#,##0.00"
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
i = i + 1
End If
Next
Dim selectRow As Integer
selectRow = startVare + antalVare
'Insert total row, 27 + format '(bruges ikke)
'If Worksheets("Prisberegning").Cells(selectRow + 1, 4).Value <> 0 Then
'
' Worksheets(currentSheet).Rows(startCell + i).Select
' Selection.Insert Shift:=xlDown
' For s = 1 To 9
' Worksheets(currentSheet).Cells(startCell + i, s) = _
' Worksheets("Prisberegning").Cells(selectRow + 1, s)
' Next
'
' Sheets(currentSheet).Select
' Rows(startCell + i).Select
' Selection.Font.Name = "Arial"
' Selection.Font.Size = 20
' Selection.Font.Bold = False
'
' Cells(startCell + i, 1).Select
' With Selection.Borders(xlEdgeLeft)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
'
' Cells(startCell + i, 4).Select
' Selection.NumberFormat = "#"
' Selection.HorizontalAlignment = xlCenter
' Cells(startCell + i, 8).Select
' Selection.NumberFormat = "#,##0.00"
' With Selection.Borders(xlEdgeRight)
' .LineStyle = xlContinuous
' .Weight = xlThin
' .ColorIndex = xlAutomatic
' End With
'
' i = i + 1
'End If
'Row 35 (licenser ialt)
Worksheets(currentSheet).Rows(startCell + i).Select
Selection.Insert Shift:=xlDown
For s = 1 To 9
Worksheets(currentSheet).Cells(startCell + i, s) = _
Worksheets("Prisberegning").Cells(selectRow + 0, s)
Next
Sheets("Prisberegning").Select
Rows(selectRow + 0).Select
Selection.Copy
Sheets(currentSheet).Select
Rows(startCell + i).Select
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
Selection.Font.Name = "Times New Roman"
Selection.Font.Size = 14
Range("A" & Target.Row & ":I" & Target.Row).Interior.ColorIndex = 15
Hilsen Jan
