formatar planilha com R$ 0.000,00 via VBA [RESOLVIDO]

JUNIOR TARGINO

05-11-2010 11:28:22

:x Estou querendo formatar as colunas b5 até m5 com o formato R$ 0.000,00 mas Não consigo porque o código que eu tenho apaga os valores anteriores. veja a linha em vermelho. Esse código filtra os valores quando eu digito em uma célula algum nome para produrar no banco de dados da planilha. AÍ é que está o problema, se eu configurar as colunas o código irá apagar ... como faço para filtrar e não apagar ? :?:
-----------------------------------------------------------------------
Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

' Verifica se o valor alterado foi na célula E1
If Not Intersect([B2], Target) Is Nothing Then

Dim lastRow As Long
Dim lastResultRow As Long
Dim x As Long

' Verifica qual a ultima célula preenchida
lastRow = Plan22.Cells(Rows.Count, 1).End(xlUp).Row

' Apaga valores anteriores
Plan23.Range("A5:M65536").Clear

lastResultRow = 5

' Ciclo em todas as linhas
For x = 2 To lastRow '1 coluna pequisa

' verifica se o valor é igual ao da pesquisa
If UCase(Plan22.Cells(x, 1).Value) = UCase(Plan23.[B2].Value) Then
'Plan22.Cells(x, 2).Value = Plan23.[F2].Value Then '1 coluna pequisa

' Copia os valores
Plan23.Cells(lastResultRow, 2).Value = Plan22.Cells(x, 2).Value
Plan23.Cells(lastResultRow, 3).Value = Plan22.Cells(x, 4).Value
Plan23.Cells(lastResultRow, 4).Value = Plan22.Cells(x, 6).Value
Plan23.Cells(lastResultRow, 5).Value = Plan22.Cells(x, 8).Value
Plan23.Cells(lastResultRow, 6).Value = Plan22.Cells(x, 10).Value
Plan23.Cells(lastResultRow, 7).Value = Plan22.Cells(x, 12).Value
Plan23.Cells(lastResultRow, 8).Value = Plan22.Cells(x, 14).Value
Plan23.Cells(lastResultRow, 9).Value = Plan22.Cells(x, 16).Value
Plan23.Cells(lastResultRow, 10).Value = Plan22.Cells(x, 18).Value
Plan23.Cells(lastResultRow, 11).Value = Plan22.Cells(x, 20).Value
Plan23.Cells(lastResultRow, 12).Value = Plan22.Cells(x, 22).Value
Plan23.Cells(lastResultRow, 13).Value = Plan22.Cells(x, 24).Value
lastResultRow = lastResultRow + 1
End If
Next
'
End If


End Sub

Agradeço a todos!!! colaboradores!!

joseA

05-11-2010 12:52:02

Seja bem vindo ao fórum. :D

Para apagar os valores anteriores sem limpar a formatação altere a linha em vermelho para:

Código: Selecionar todos

Plan23.Range("A5:M65536").ClearContents