
if condizione then
With tuorange
.Merge
.Font.Underline = xlUnderlineStyleSingle
End With
end if |
Option Explicit
Sub Settimane()
Dim Sh As Worksheet, Lr As Long, Lr1 As Long
Dim i As Long, x As Long, n As Long, SetNum As Integer
Dim Setm(), DataIn As Long, DataFin As Long, LastCol As Long
Dim GiornoIn As Integer, GiornoFin As Integer
Dim MeseIn As Integer, MeseFin As Integer
Dim SetIn As Integer, SetFin As Integer
Set Sh = Worksheets("Rr")
Lr = Sh.Cells(Rows.Count, 2).End(xlUp).Row
Lr1 = Sh.Cells(Rows.Count, 4).End(xlUp).Row
If Lr1 < 14 Then Lr1 = 14
LastCol = Sh.Cells(14, Columns.Count).End(xlToLeft).Column
Setm = Array(SetIn, SetFin)
With Sh.Range(Cells(15, 4), Cells(Lr1 + 1, LastCol))
.ClearContents
.UnMerge
.Borders(xlEdgeLeft).LineStyle = xlNone
.Borders(xlEdgeTop).LineStyle = xlNone
.Borders(xlEdgeBottom).LineStyle = xlNone
.Borders(xlEdgeRight).LineStyle = xlNone
.Borders(xlInsideVertical).LineStyle = xlNone
.Interior.Color = xlNone
End With
Lr1 = 14
For i = 4 To Lr
If IsDate(Sh.Cells(i, 4).Value) And IsDate(Sh.Cells(i, 5).Value) Then
DataIn = Sh.Cells(i, 4).Value
DataFin = Sh.Cells(i, 5).Value
Setm(0) = WorksheetFunction.WeekNum(DataIn, 2)
Setm(1) = WorksheetFunction.WeekNum(DataFin, 2)
If Setm(0) <= Setm(1) Then
For x = 0 To 1
For n = 6 To LastCol
SetNum = Val(Right(Sh.Cells(14, n).Value, Len(Sh.Cells(14, n).Value) - 2))
If SetNum = Setm(x) Then
Setm(x) = n
Exit For
End If
Next n
Next x
Lr1 = Lr1 + 1
With Sh.Range(Cells(Lr1, 4), Cells(Lr1, LastCol))
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
End With
Sh.Cells(Lr1, 4).Value = Sh.Cells(i, 3).Value
Sh.Cells(Lr1, 5).Value = Sh.Cells(i, 2).Value
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Merge
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Interior.Color = RGB(255, 155, 102)
GiornoIn = Day(DataIn): MeseIn = Month(DataIn)
GiornoFin = Day(DataFin): MeseFin = Month(DataFin)
Sh.Cells(Lr1, Setm(0)).Value = GiornoIn & "/" & MeseIn & " - " & GiornoFin & "/" & MeseFin
End If
End If
Next i
Set Sh = Nothing
End Sub
|
With Sh.Range(Cells(15, 4), Cells(Lr1 + 1, LastCol))
.ClearContents
.UnMerge
.Borders.LineStyle = xlNone
.Interior.Color = xlNone
End With
With Sh.Range(Cells(Lr1, 4), Cells(Lr1, LastCol))
.Borders.LineStyle = xlContinuous
End With |
Option Explicit
Sub Settimane()
Dim Sh As Worksheet, Lr As Long, Lr1 As Long
Dim i As Long, x As Long, n As Long, SetNum As Integer
Dim Setm(), DataIn As Long, DataFin As Long, LastCol As Long
Dim GiornoIn As Integer, GiornoFin As Integer
Dim MeseIn As Integer, MeseFin As Integer, Trovato As Boolean
Dim SetIn As Integer, SetFin As Integer
Set Sh = Worksheets("Rr")
Lr = Sh.Cells(Rows.Count, 2).End(xlUp).Row
Lr1 = Sh.Cells(Rows.Count, 4).End(xlUp).Row
If Lr1 < 14 Then Lr1 = 14
LastCol = Sh.Cells(14, Columns.Count).End(xlToLeft).Column
Setm = Array(SetIn, SetFin)
With Sh.Range(Cells(15, 4), Cells(Lr1 + 1, LastCol))
.ClearContents
.UnMerge
.Borders.LineStyle = xlNone
.Interior.Color = xlNone
End With
Lr1 = 14
For i = 4 To Lr
If IsDate(Sh.Cells(i, 4).Value) And IsDate(Sh.Cells(i, 5).Value) Then
DataIn = Sh.Cells(i, 4).Value
DataFin = Sh.Cells(i, 5).Value
Setm(0) = WorksheetFunction.WeekNum(DataIn, 2)
Setm(1) = WorksheetFunction.WeekNum(DataFin, 2)
If Setm(0) <= Setm(1) Then
For x = 0 To 1
Trovato = False
For n = 6 To LastCol
SetNum = Val(Right(Sh.Cells(14, n).Value, Len(Sh.Cells(14, n).Value) - 2))
If SetNum = Setm(x) Then
Setm(x) = n
Trovato = True
Exit For
End If
Next n
Next x
If Trovato = False Then
MsgBox "Settimana per la categoria " & Sh.Cells(i, 3).Value & " non trovata"
Else
Lr1 = Lr1 + 1
Sh.Range(Cells(Lr1, 4), Cells(Lr1, LastCol)).Borders.LineStyle = xlContinuous
Sh.Cells(Lr1, 4).Value = Sh.Cells(i, 3).Value
Sh.Cells(Lr1, 5).Value = Sh.Cells(i, 2).Value
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Merge
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Interior.Color = RGB(255, 155, 102)
GiornoIn = Day(DataIn): MeseIn = Month(DataIn)
GiornoFin = Day(DataFin): MeseFin = Month(DataFin)
Sh.Cells(Lr1, Setm(0)).Value = GiornoIn & "/" & MeseIn & " - " & GiornoFin & "/" & MeseFin
End If
Else
MsgBox "Data Finale inferiore a data Iniziale categoria " & Sh.Cells(i, 3).Value
End If
Else
MsgBox "Controllare la validità o la presenza delle date per la categoria " & Sh.Cells(i, 3).Value
End If
Next i
Set Sh = Nothing
End Sub
|
Option Explicit
Sub Settimane()
Dim Sh As Worksheet, Lr As Long, Lr1 As Long
Dim i As Long, x As Long, n As Long, SetNum As Integer
Dim Setm(), DataIn As Long, DataFin As Long, LastCol As Long
Dim GiornoIn As Integer, GiornoFin As Integer
Dim MeseIn As Integer, MeseFin As Integer, Trovato As Boolean
Dim SetIn As Integer, SetFin As Integer
Set Sh = Worksheets("Rr")
Lr = Sh.Cells(Rows.Count, 2).End(xlUp).Row
Lr1 = Sh.Cells(Rows.Count, 4).End(xlUp).Row
If Lr1 < 14 Then Lr1 = 14
LastCol = Sh.Cells(14, Columns.Count).End(xlToLeft).Column
Setm = Array(SetIn, SetFin)
With Sh.Range(Cells(15, 4), Cells(Lr1 + 1, LastCol))
.ClearContents
.UnMerge
.Borders.LineStyle = xlNone
.Interior.Color = xlNone
End With
Lr1 = 14
For i = 4 To Lr
If IsDate(Sh.Cells(i, 4).Value) And IsDate(Sh.Cells(i, 5).Value) Then
If Sh.Cells(i, 4).Value <= Sh.Cells(i, 5).Value Then
DataIn = Sh.Cells(i, 4).Value
DataFin = Sh.Cells(i, 5).Value
Setm(0) = WorksheetFunction.WeekNum(DataIn, 2)
Setm(1) = WorksheetFunction.WeekNum(DataFin, 2)
For x = 0 To 1
Trovato = False
For n = 6 To LastCol
SetNum = Val(Right(Sh.Cells(14, n).Value, Len(Sh.Cells(14, n).Value) - 2))
If SetNum = Setm(x) Then
Setm(x) = n
Trovato = True
Exit For
End If
Next n
Next x
If Trovato = False Then
MsgBox "Settimana per la categoria " & Sh.Cells(i, 3).Value & " non trovata"
Else
Lr1 = Lr1 + 1
Sh.Range(Cells(Lr1, 4), Cells(Lr1, LastCol)).Borders.LineStyle = xlContinuous
Sh.Cells(Lr1, 4).Value = Sh.Cells(i, 3).Value
Sh.Cells(Lr1, 5).Value = Sh.Cells(i, 2).Value
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Merge
Sh.Range(Cells(Lr1, Setm(0)), Cells(Lr1, Setm(1))).Interior.Color = RGB(255, 155, 102)
GiornoIn = Day(DataIn): MeseIn = Month(DataIn)
GiornoFin = Day(DataFin): MeseFin = Month(DataFin)
Sh.Cells(Lr1, Setm(0)).Value = GiornoIn & "/" & MeseIn & " - " & GiornoFin & "/" & MeseFin
End If
Else
MsgBox "Data Finale inferiore a data Iniziale categoria " & Sh.Cells(i, 3).Value
End If
Else
MsgBox "Controllare la validità o la presenza delle date per la categoria " & Sh.Cells(i, 3).Value
End If
Next i
Set Sh = Nothing
End Sub
|
