Ir ao conteúdo
  • Cadastre-se

Excel Tratar texto excel com Função Vba


Ir à solução Resolvido por Muca Costa,

Posts recomendados

Bom dia a todos!
Então, eu tenho as seguintes células 

A1    9189-SINDICATO DOS RATIFICANTES NO CO  134534222164 NF:43520 PLC:

A2    8445-ACIL - ASSOCIAÇAO COMERCIAL. I  4353546 NF:543530 PLC:

A3    2110-TV SP2 COMUNICAÇÕES LTDA  07/2020L NF:34530 PLC: 

A4

A5

...

 

Eu gostaria de saber se alguém sabe de alguma função em vba que traz os valores antes de encontrarem um  número ou um "." ou uma barra. Dessa forma ela ia me retornar as células assim 

 

9189-SINDICATO DOS EMPREGADOS NO CO

8445-ACIL - ASSOCIAÇAO COMERCIAL

2110-TV SP2 COMUNICAÇÕES LTDA

 

Desde já eu agradeço. 

 

Link para o comentário
Compartilhar em outros sites

  • Solução

Veja se ajuda: Execute a Sub Arrumar()

 

Sub Arrumar()
    Extrair
    Excluir
    Finalizar
    Columns("A:B").Select
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
End Sub
Sub Extrair()
Dim P As String, Ultimalinha As String, Lin As String, i As Integer
With ActiveSheet
  P = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
  Ultimalinha = Planilha1.Cells(Rows.Count, "A").End(xlUp).Row
  Lin = 1
  For i = 1 To Ultimalinha
      Planilha1.Cells(Lin, 2) = Left(Planilha1.Cells(i, 1), 5)
      Lin = Lin + 1
  Next
End Sub

Sub Excluir()
 Dim LR As Long, k As Long
 LR = Cells(Rows.Count, "A").End(xlUp).Row
  Application.ScreenUpdating = False
  For k = LR To 1 Step -1
   If Cells(k, "A").Value <> "" Then
    c1 = Cells(k, "A").Replace("NF:", "", xlPart)
    c2 = Cells(k, "A").Replace("/", "", xlPart)
    c3 = Cells(k, "A").Replace("PLC:", "", xlPart)
    c4 = Cells(k, "A").Replace(". I ", "", xlPart)
    c5 = Cells(k, "A").Replace(".", "", xlPart)
    c6 = Cells(k, "A").Replace("-", "", xlPart)
    c7 = Cells(k, "A").Replace("0", "", xlPart)
    c8 = Cells(k, "A").Replace("1", "", xlPart)
    c9 = Cells(k, "A").Replace("2", "", xlPart)
    c10 = Cells(k, "A").Replace("3", "", xlPart)
    c11 = Cells(k, "A").Replace("4", "", xlPart)
    c12 = Cells(k, "A").Replace("5", "", xlPart)
    c13 = Cells(k, "A").Replace("6", "", xlPart)
    c14 = Cells(k, "A").Replace("7", "", xlPart)
    c15 = Cells(k, "A").Replace("8", "", xlPart)
    c16 = Cells(k, "A").Replace("9", "", xlPart)
    c17 = Cells(k, "A").Replace("/", "", xlPart)
   End If
  Next k
  Application.ScreenUpdating = True
      Range("A1").Select
End Sub

Sub Finalizar()
Dim P As String, Ultimalinha As String, Lin As String, i As Integer
With ActiveSheet
  P = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
  Ultimalinha = Planilha1.Cells(Rows.Count, "A").End(xlUp).Row
  Lin = 1
  For i = 1 To Ultimalinha
      Planilha1.Cells(Lin, 3) = Planilha1.Cells(i, 2) & Planilha1.Cells(i, 1)
      Lin = Lin + 1
  Next
End Sub

 

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

  • 4 semanas depois...

Crie uma conta ou entre para comentar

Você precisa ser um usuário para fazer um comentário

Criar uma conta

Crie uma nova conta em nossa comunidade. É fácil!

Crie uma nova conta

Entrar

Já tem uma conta? Faça o login.

Entrar agora

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...