Jump to content

Recommended Posts

Posted

imaginem que giro um hotel

na Folha1 tenho um mapa com uma coluna para os hóspedes, outra que informa se já saíram ou ainda estão hospedados

o que pretendo é ter na Folha2 uma coluna, sem linhas em branco, dos hóspedes que estão actualmente no hotel (hospedado=verdade)

posso postar o código que tenho até agora, o qual faz tudo, embora a solução não me agrade de todo

a razão é que é um macro: tendo a minha folha mais de 1000 linhas, com o apagar das células em branco a pág fica muitos segundos como que a fazer refresh, o que é francamente desagradável

eu tenho um excel com exemplo, mas não sei anexá-lo aqui

alguém terá alguma maneira alternativa de resolver isto?

obrigado antecipadamente

Posted

quero agradecer aqui ao Jorge a excelente ajuda que ele deu, e sem a qual eu não teria o meu problema resolvido

obrigado Jorge!

aqui fica o código

Folha1

Option Explicit

Sub Localiza()

Dim row As Integer

Dim i As Integer

Folha2.Columns("C").ClearContents

i = 1

row = 1

For i = 1 To Cells(Cells.Rows.Count, "a").End(xlUp).row

    If Cells(i, "B") = "aberto" Then

   

        Folha2.Range("c" & row) = Range("A" & i)

        row = row + 1

    End If

Next

End Sub

Private Sub Worksheet_Activate()

    Call Localiza

End Sub

Folha2

Sub escreve()

Application.ScreenUpdating = False

Dim i, contador As Integer

Dim oRange As Range

Dim cabeçalho As String

cabeçalho = "Títulos em carteira"

Set oRange = Folha1.Range("A:A")

contador = Application.WorksheetFunction.CountA(oRange)

'For i = dataCount To 1 Step -1

For i = contador To 2 Step -1 'assim posso ter rótulo

    If Range("c" & i) = "" Then

    Range("c" & i).Select

    Selection.Delete Shift:=xlUp

    End If

   

Next

Range("c1").Value = cabeçalho 'rótulo

Application.ScreenUpdating = True

End Sub

Private Sub Worksheet_Activate()

    Call escreve

End Sub

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
×
×
  • 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.