Como dividir e organizar os dados do Excel em Páginas

Descubra como simplificar a organização de grandes conjuntos de dados no Excel com esta abordagem prática de divisão e organização em páginas. Este guia passo a passo irá ajudá-lo a a dividir e organizar os dados de Planilhas do Excel em seções gerenciáveis, facilitando a análise e a colaboração. Através das técnicas ensinadas nesse Post, você poderá buscar e visualizar os dados de forma mais fácil, rápida e agradável. 🚀✨

Contextualização

Já se sentiu perdido em uma planilha gigante do Excel? Eu também! Mas descobri um jeito de facilitar muito: dividir e organizar os dados em páginas.

 

Essa técnica não só ajuda a encontrar informações mais rápido, mas também deixa a visualização muito mais clara. Imagina poder clicar em botões numerados e ir direto para a parte que interessa? É possível! E vou te mostrar como fazer isso neste post. Venha comigo e vamos deixar suas planilhas mais fáceis de usar e entender!

Criação dos botões das Páginas

Vamos criar botões numerados para facilitar a navegação na sua planilha. Estes botões são mais do que simples retângulos com números. Eles são seus atalhos para uma análise mais rápida e eficiente. Com a automação do VBA (Visual Basic for Applications), cada número em seu botão será sua passagem para uma seção específica dos seus dados.

Crie uma Planilha e defina a quantidade de registros por página

Crie a quantidade de botões desejado e organize-os

  1. Selecione a opção “Inserir” na barra de ferramentas do Excel.

  2. Escolha “Formas” e selecione o retângulo.

  3. Desenhe o retângulo na sua planilha e adicione um número dentro dele.

  4. Repita o processo para cada número que deseja como botão.

Renomeie os botões

Os nomes que você irá usar são de extrema importância, pois será por meio deles que você irá desenvolver os códigos de alternância e paginação dos dados.

Para renomear, basta usar o atalho do teclado ALT+F10, e no painel mostrado, clicar duas vezes nos nomes padrão e renomeá-los.

Acesse o VBE para criar os códigos

 

  1. Agora, pressione “Alt + F11” para abrir o Editor do VBA.

  2. Na janela do Editor, insira o código VBA para cada botão, atribuindo a ação de navegar para a página desejada quando clicado. Por exemplo:

				
					Sub Pagina1()
    'código aqui
End Sub
				
			

Criação dos códigos de alternância de cor dos botões

Antes de criar propriamente os acessos as respectivas paginas, iremos criar a personalização dos botões a medida que eles são acionados. Em outras palavras, sempre que você clicar  em um determinado botão, ele receberá uma cor especifica, enquanto os demais são resetados para a sua cor padrão. Faremos isso individualmente para cada botão.

O código ficará da seguinte forma:

				
					Sub Pagina1()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(255, 51, 0)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        
End Sub

Sub Pagina2()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(255, 51, 0)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        
End Sub

Sub Pagina3()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(255, 51, 0)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        
End Sub

Sub Pagina4()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(255, 51, 0)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        
End Sub

Sub Pagina5()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        
End Sub

Sub Pagina6()

    Dim Plan As Worksheet
    
    Set Plan = Planilha1
    
    Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(255, 51, 0)
        
End Sub
				
			

Para ver o resultado acontecer na prática, você precisará atribuir, individualmente, cada procedimento ao seu respectivo botão. 

Logo, o botão da página 1 receberá o procedimento “Página1”, o botão 2, receberá o procedimento “Pagina2”, e assim por diante.

Para fazer, isso, vá até o botão e clique com o botão direito do mouse, em seguida clique em atribuir macro e selecione o procedimento desejado para cada botão.

Ao fazer isso para todos os botões, você pode agora, ver o resultado acontecer a medida que clica em um botão ou outro da sua planilha de Excel.

Definição da última página de acordo com a quantidade de registros

A última página da sua lista de dados do Excel, dependerá da quantidade de registros presentes na planilha que contem os dados brutos, e também da definição da quantidade de registros por páginas. 

A quantidade de registros a ser exibida por página, já foi definida, no nosso caso, definimos 20 registros. Logo, o numero da ultima pagina pode ser definido pela divisão entre a quantidade total de registros a ser consultado e a quantidade de registros por página, nesse caso, 20.

Como o resultado poderá ter valor fracionário, será necessário fazer um arredondamento para o numero inteiro mais próximo, respeitando a exibição de todos os registros.

O resultado da divisão deve ser colocado dentro de uma célula do Excel, para em seguida ser colocado dentro do botão da última página. A formula a ser usado, pode ser a seguinte:

				
					=ARRED( (CONT.VALORES(Planilha2!A:A) -1)/20;1)
				
			

Para inserir o valor da célula dentro do botão da ultima pagina, basta clicar sob o botão, clicar dentro da barra fórmula, digitar “=” e clicar sob a célula com o resultado. Dessa forma, sempre o resultado da célula mudar, o numero dentro do botão também mudará.

Renovando a numerção das páginas

Suponha que você queira clicar na página de número 5 e fazer com que essa página venha para a posição da página 1 e que as páginas a seguir seja acrescidas, conforme a imagens abaixo.

Nosso código agora, precisará ficar da seguinte forma:

				
					Dim Plan As Worksheet

Sub Pagina1()

Dim x As Integer

Set Plan = Planilha1

x = Plan.Shapes("pg1").TextFrame.Characters.text

Select Case x
    Case Is = 1
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(255, 51, 0)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Case Is > 5
        Plan.Shapes("pg5").TextFrame.Characters.text = x
        Plan.Shapes("pg4").TextFrame.Characters.text = x - 1
        Plan.Shapes("pg3").TextFrame.Characters.text = x - 2
        Plan.Shapes("pg2").TextFrame.Characters.text = x - 3
        Plan.Shapes("pg1").TextFrame.Characters.text = x - 4

        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)

    Case Is < 5
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg" & x).Fill.ForeColor.RGB = RGB(255, 51, 0)
        For x = 1 To 5
            Plan.Shapes("pg" & x).TextFrame.Characters.text = x
        Next

    Case Is = 5
        For x = 1 To 5
            Plan.Shapes("pg" & x).TextFrame.Characters.text = x
        Next
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)

End Select

End Sub

Sub Pagina2()

Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

End Sub

Sub Pagina3()

Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

End Sub

Sub Pagina4()

Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

End Sub

Sub Pagina5()

On Error Resume Next

Dim x As Integer, y As Integer, z As Integer, w As Integer, u As Integer

Set Plan = Planilha1

z = Plan.Shapes("pg5").TextFrame.Characters.text
w = Plan.Shapes("pg1").TextFrame.Characters.text

u = Plan.Shapes("pg6").TextFrame.Characters.text
x = u - w

Select Case x
    Case Is = 0
        Exit Sub
    Case Is > 5
        Plan.Shapes("pg1").TextFrame.Characters.text = z
        Plan.Shapes("pg2").TextFrame.Characters.text = z + 1
        Plan.Shapes("pg3").TextFrame.Characters.text = z + 2
        Plan.Shapes("pg4").TextFrame.Characters.text = z + 3
        Plan.Shapes("pg5").TextFrame.Characters.text = z + 4
    Case Is <= 5
        y = 0
        If z = u Then
            Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)
            Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Exit Sub
        End If
        For x = 5 To 1 Step -1
            Plan.Shapes("pg" & x).TextFrame.Characters.text = u - y
            y = y + 1
        Next
End Select

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

End Sub

Sub Pagina6()

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(255, 51, 0)

End Sub
				
			

Listagem dos registros ao clicar nas páginas

Para listar os dados de acordo com os registros atribuídos a cada página, iremos definir um novo procedimento. Esse procedimento irá conter um paramento chamado “offset”, que será um numero correspondente ao “salto” necessário para alcançar a linha inicial correta para iniciar a busca dos dados.

Para isso, usaremos o seguinte procedimento:

				
					Sub realizaOffset(offset As Integer)

    Dim Pl1 As Worksheet, Pl2 As Worksheet
    Dim col As Integer, i As Long, j As Integer
    
    Set Pl1 = Planilha1
    Set Pl2 = Planilha2

    Pl1.Range("B6:I55").ClearContents
        
    i = 6
    col = 1
    
    For j = 1 To 20
            
            DoEvents
            Pl1.Cells(i, col + 1).Value = Pl2.Cells(j, col).offset(offset + 1, 0).Value
            Pl1.Cells(i, col + 2).Value = Pl2.Cells(j, col).offset(offset + 1, 1).Value
            Pl1.Cells(i, col + 3).Value = Pl2.Cells(j, col).offset(offset + 1, 2).Value
            Pl1.Cells(i, col + 4).Value = Pl2.Cells(j, col).offset(offset + 1, 3).Value
            Pl1.Cells(i, col + 5).Value = Pl2.Cells(j, col).offset(offset + 1, 4).Value
            Pl1.Cells(i, col + 6).Value = Pl2.Cells(j, col).offset(offset + 1, 5).Value
            Pl1.Cells(i, col + 7).Value = Pl2.Cells(j, col).offset(offset + 1, 6).Value
            Pl1.Cells(i, col + 8).Value = Pl2.Cells(j, col).offset(offset + 1, 7).Value
            i = i + 1
     Next j


End Sub
				
			

Agora precisamos chamar esse procedimento dentro de cada um dos botões das páginas. Para isso, escrevemos o nome do procedimento dentro de cada um dos procedimentos das páginas, usando como argumento o valor de “offset” de cada página. O valor de “offset” de cada página será o numero da página multiplicado por 20, que é a quantidade de registros de cada página.

Logo, reescrevemos os procedimentos da seguinte maneira:

				
					Dim Plan As Worksheet

Sub Pagina1()

On Error Resume Next

Dim x As Integer, y As Integer

Set Plan = Planilha1

x = Plan.Shapes("pg1").TextFrame.Characters.text

y = (x - 1) * 20

Select Case x
    Case Is = 1
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(255, 51, 0)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
    Case Is > 5
        Plan.Shapes("pg5").TextFrame.Characters.text = x
        Plan.Shapes("pg4").TextFrame.Characters.text = x - 1
        Plan.Shapes("pg3").TextFrame.Characters.text = x - 2
        Plan.Shapes("pg2").TextFrame.Characters.text = x - 3
        Plan.Shapes("pg1").TextFrame.Characters.text = x - 4

        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)

    Case Is < 5
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg" & x).Fill.ForeColor.RGB = RGB(255, 51, 0)
        For x = 1 To 5
            Plan.Shapes("pg" & x).TextFrame.Characters.text = x
        Next

    Case Is = 5
        For x = 1 To 5
            Plan.Shapes("pg" & x).TextFrame.Characters.text = x
        Next
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)

End Select

Planilha1.pesq_tx.Value = ""

On Error GoTo 0

realizaOffset (y)

End Sub

Sub Pagina2()

On Error Resume Next
Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

x = Plan.Shapes("pg2").TextFrame.Characters.text

x = (x - 1) * 20
On Error GoTo 0

realizaOffset (x)

End Sub

Sub Pagina3()

On Error Resume Next
Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

x = Plan.Shapes("pg3").TextFrame.Characters.text

x = (x - 1) * 20
On Error GoTo 0

realizaOffset (x)

End Sub

Sub Pagina4()

On Error Resume Next

Dim x As Integer

Set Plan = Planilha1

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

x = Plan.Shapes("pg4").TextFrame.Characters.text

x = (x - 1) * 20

On Error GoTo 0

realizaOffset (x)

End Sub

Sub Pagina5()

On Error Resume Next

Dim x As Integer, y As Integer, z As Integer, w As Integer, u As Integer

Set Plan = Planilha1

z = Plan.Shapes("pg5").TextFrame.Characters.text
w = Plan.Shapes("pg1").TextFrame.Characters.text

u = Plan.Shapes("pg6").TextFrame.Characters.text
x = u - w

Select Case x
    Case Is = 0
        Exit Sub
    Case Is > 5
        Plan.Shapes("pg1").TextFrame.Characters.text = z
        Plan.Shapes("pg2").TextFrame.Characters.text = z + 1
        Plan.Shapes("pg3").TextFrame.Characters.text = z + 2
        Plan.Shapes("pg4").TextFrame.Characters.text = z + 3
        Plan.Shapes("pg5").TextFrame.Characters.text = z + 4
    Case Is <= 5
        y = 0
        If z = u Then
            Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(255, 51, 0)
            Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
            Exit Sub
        End If
        For x = 5 To 1 Step -1
            Plan.Shapes("pg" & x).TextFrame.Characters.text = u - y
            y = y + 1
        Next
End Select

Planilha1.pesq_tx.Value = ""

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(255, 51, 0)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

z = (z - 1) * 20

On Error GoTo 0

realizaOffset (z)

End Sub

Sub Pagina6()

On Error Resume Next

Dim x As Integer

Set Plan = Planilha1

x = Plan.Shapes("pg6").TextFrame.Characters.text

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(255, 51, 0)

x = (x - 1) * 20

Planilha1.pesq_tx.Value = ""

On Error GoTo 0

realizaOffset (x)

End Sub
				
			

Listagem dos registros ao clicar nas páginas

Para finalizar, definimos um método de busca especifica por página. Com essa opção, o usuário poderá navegar até uma pagina especifica, mesmo que a mesma não esteja listada pelos botões. 

				
					Sub BuscaEspecifica()

On Error Resume Next

Dim vPag As Long
Dim uPag As Integer

Set Plan = Planilha1

If Planilha1.pesq_tx.Value = "" Then
    MsgBox "Infome a Página desejada!", vbExclamation, "Valor não permitido!"
    Exit Sub
End If

vPag = Planilha1.pesq_tx.Value
uPag = Plan.Shapes("pg6").TextFrame.Characters.text

If Not IsNumeric(vPag) Then
    MsgBox "Insira um valor válido!", vbExclamation, "Valor não permitido!"
    Exit Sub
ElseIf vPag > uPag Then
    MsgBox "Essa página não existe!", vbExclamation, "Página inexistente!"
    Exit Sub
ElseIf vPag < 1 Then
    MsgBox "Insira um valor válido!", vbExclamation, "Valor não permitido!"
    Exit Sub
End If

Dim x As Integer, y As Integer

x = uPag
x = x - vPag

Select Case x
    Case Is = 0
        Plan.Shapes("pg1").TextFrame.Characters.text = vPag - 5
        Plan.Shapes("pg2").TextFrame.Characters.text = vPag - 4
        Plan.Shapes("pg3").TextFrame.Characters.text = vPag - 3
        Plan.Shapes("pg4").TextFrame.Characters.text = vPag - 2
        Plan.Shapes("pg5").TextFrame.Characters.text = vPag - 1
        
        Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)
        Exit Sub
    Case Is > 5
        Plan.Shapes("pg1").TextFrame.Characters.text = vPag - 5
        Plan.Shapes("pg2").TextFrame.Characters.text = vPag - 4
        Plan.Shapes("pg3").TextFrame.Characters.text = vPag - 3
        Plan.Shapes("pg4").TextFrame.Characters.text = vPag - 2
        Plan.Shapes("pg5").TextFrame.Characters.text = vPag - 1
    Case Is <= 5
        y = 1
        For x = 5 To 1 Step -1
            Plan.Shapes("pg" & x).TextFrame.Characters.text = vPag - y
            y = y + 1
        Next
End Select

Plan.Shapes("pg1").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg2").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg3").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg4").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg5").Fill.ForeColor.RGB = RGB(102, 0, 255)
Plan.Shapes("pg6").Fill.ForeColor.RGB = RGB(102, 0, 255)

x = Planilha1.pesq_tx.Value

x = (x - 1) * 20

On Error GoTo 0

realizaOffset (x)
        
End Sub
				
			

curso

Programando o Excel com VBA (do Básico ao Profissional)

curso

Controle de Acesso e Permissões de Usuários aplicados à Ribbon do Excel