Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
  • Avatar do usuário
Por VINICIUSGOLTARA
#30036
PODERIAM ME AJUDAR A CRIAR MACRO PARA INSERÇÃO DE LINHAS ATENDENDO AS SEGUINTES ESPECIFICAÇÕES:

ABAIXO TRANSCREVO PARTE DA TABELA, NECESSITO QUE SEJA ADICIONADO UMA LINHA ANTES DA PRIMEIRA LINHA QUE CONTENHA A DESCRIÇÃO ""EUR" E UMA LINHA ANTES DA ULTIMA DESRIÇÃO "CUR E "CMI".

AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO EUR - R01
AFONSO CLAUDIO AC AFONSO CLAUDIO EUR ROTA EXCLUSIVA R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CUR ROTA EXCLUSIVA R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI - R01
AFONSO CLÁUDIO AFONSO CLAUDIO AC AFONSO CLAUDIO CMI ROTA EXCLUSIVA R01


OBRIGADO.
Por Feka
Posts
#30037
Boa tarde,

Teste esse código, para mim deu certo. Só fique atento para ajustar o nome da planilha e a range.

Eu joguei os dados que você colocou em uma coluna A
Código: Selecionar todos
Sub ttest()

'Atribuição de variável

Dim a As Long, b As Long, c As Long

b = 0
c = 0



'Atuando no Eur
For a = 1 To Planilha2.Range("a1048576").End(xlUp).Row
   If InStr(1, Planilha2.Cells(a, 1), " eur", vbTextCompare) > 1 Then
   Planilha2.Cells(a, 1).EntireRow.Insert
   Exit For
   End If
   Next
   
   
For a = 1 To Planilha2.Range("a1048576").End(xlUp).Row
   If InStr(1, Planilha2.Cells(a, 1), " cur", vbTextCompare) > 1 Then
   b = b + 1
   End If
   Next
       
'Atuando no cur
For a = 1 To Planilha2.Range("a1048576").End(xlUp).Row
   If InStr(1, Planilha2.Cells(a, 1), " cur", vbTextCompare) > 1 Then
   c = c + 1
    If c = b Then
     Planilha2.Cells(a, 1).EntireRow.Insert
     Exit For
    End If
   End If
   Next
   
b = 0
c = 0

   
'Atuando no cmi
For a = 1 To Planilha2.Range("a1048576").End(xlUp).Row
   If InStr(1, Planilha2.Cells(a, 1), " cmi", vbTextCompare) > 1 Then
   b = b + 1
   End If
   Next
       
For a = 1 To Planilha2.Range("a1048576").End(xlUp).Row
   If InStr(1, Planilha2.Cells(a, 1), " cmi", vbTextCompare) > 1 Then
   c = c + 1
    If c = b Then
     Planilha2.Cells(a, 1).EntireRow.Insert
     Exit For
    End If
   End If
   Next


End Sub
Por VINICIUSGOLTARA
#30040
Perdoe-me a ignorância, mas retornou erro, acredito que eu não tenha feito as modificações corretas.
Tentarei especificar melhor como esta a planilha.


ES | CIdade 1 | cidade1 | Unidade | EUR
ES | CIdade 1 | cidade1 | Unidade | EUR
ES | CIdade 1 | cidade1 | Unidade | CUR
ES | CIdade 1 | cidade1 | Unidade | CUR
ES | CIdade 1 | cidade1 | Unidade | CMI
ES | CIdade 1 | cidade1 | Unidade | CMI...


Grato.
Avatar do usuário
Por Dieferson
Posts Avatar
#30047
Vinicius, boa noite!

Se postar a planilha só com um exemplo fica mais fácil pra responder.

até..
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord