terramoto Posted February 24, 2012 at 01:23 PM Report Share #440999 Posted February 24, 2012 at 01:23 PM Boas, tenho esta função no excel, mas quando corre o set sabador não guarda a range, todas as variáveis que vão no .Range() estão preenchidas. Function Cria_Tabela(ByVal alcance As String, sabador, domingor, linhai, linhaf) limite = Split(alcance, ":") Worksheets("Sheet2").Range(alcance).ClearContents 'Este For mete os dias da semana na tabela For c = 3 To Worksheets("Sheet2").Range(alcance).Count Step 4 DiaS = Choose(Weekday(CDate(Calendar1.Value), vbMonday), "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "Sabado", "Domingo") 'Se for sabado registra o dia ignora If DiaS = "Sabado" Then With Worksheets("sheet2") Set sabador = .Range(Cells(linhai, c), Cells(linhaf, c + 3)) End With If Calendar1.Day = 1 Then Calendar1.Day = 3 ElseIf Calendar1.Day >= 2 Then Worksheets("Sheet2").Range(sabador, limite(1)).HorizontalAlignment = xlHAlignCenter 'Exit For End If 'Se for domingo registra o dia e ignora ElseIf DiaS = "Domingo" Then Set domingor = Worksheets("Sheet2").Range(Cells(linhai, c), Cells(linhaf, c + 3)) If Calendar1.Day = 1 Then Calendar1.Day = 2 ElseIf Calendar1.Day = 2 Then Worksheets("Sheet2").Range(domingor, limite(0)).HorizontalAlignment = xlHAlignCenter End If End If 'Se nao for sabado nem domingo cria a tabela If (Calendar1.Day <= 7) Then Worksheets("Sheet2").Range(Cells(linhai, c), Cells(linhaf, c + 3)).HorizontalAlignment = xlHAlignCenterAcrossSelection Cells(linhai, c).Value = Choose(Weekday(CDate(Calendar1.Value), vbMonday), "Segunda", "Terça", "Quarta", "Quinta", "Sexta", "", "") Cells(linhai + 1, c).Value = "Peso" Cells(linhai + 1, c + 1).Value = "Obj Efectivo" Cells(linhai + 1, c + 2).Value = "Real" Cells(linhai + 1, c + 3).Value = "Diferenca" End If If (Calendar1.Day = 7) Or (Calendar1.Day = 14) Or (Calendar1.Day = 21) Or (Calendar1.Day = 28) Then c = c + 4 ElseIf Calendar1.Day = Udia Then Exit For End If Calendar1.Day = Calendar1.Day + 1 Next c End Function A great truth is a truth whose opposite is also a great truth. Link to comment Share on other sites More sharing options...
terramoto Posted February 24, 2012 at 03:16 PM Author Report Share #441019 Posted February 24, 2012 at 03:16 PM já percebi o problema, if calendar1.day<=7 then Worksheets("Sheet2").Range(Cells(linhai, c), Cells(linhaf, c + 3)).HorizontalAlignment = xlHAlignCenterAcrossSelection estava a sobrepor o outro. Já agora, se alguém me poder dar umas dicas onde posso simplificar.... A great truth is a truth whose opposite is also a great truth. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now