Jump to content

Set Range não está a funcionar...


terramoto
 Share

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.