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.
Por rafael84
Posts
#51080
Não consegui reabrir o tópico que avia criado e fechado. Este:
viewtopic.php?f=12&t=11099

Mostrei um exemplo do que precisava e um usuário montou uma macro que funciona perfeitamente. Mas estou tentando ajustar para o meu caso real e não estou conseguindo, não estou entendendo como setar o SpecialCells e .Resize. Está bem confuso. No meu caso real (em anexo) eu preciso uma macro que pegue a FOLHA1 e a transforme ficando como a FOLHA2. O comando de mesclar deve ser feito verificando pela coluna sequencial.

O código do usuário osvaldomp é este:
Código: Selecionar todos
Sub RearranjaDados()
 Dim a As Range, x As Long, v As Long, n As Long
  Application.ScreenUpdating = False
  Columns("I:L").Clear
  For Each a In Columns(1).SpecialCells(2).Areas
   If a.Cells(1) Like "*sequencial*" Then
    Cells(a.Row, 9).Resize(, 4).Value = a.Cells(1).Resize(, 4).Value
    x = a.Cells(1).End(4).Row
    Cells(a.Row + 1, 12).Resize(x - a.Row).Value = a.Cells(2, 4).Resize(x - a.Row).Value
    For n = a.Row + 1 To x
     Cells(n, 9).Resize(, 3).Value = Cells(n, 1).Resize(, 3).Value
     v = Application.CountIf(Cells(n, 1).Resize(x - a.Row), Cells(n, 1))
     Cells(n, 9).Resize(v).Merge: Cells(n, 10).Resize(v).Merge: Cells(n, 11).Resize(v).Merge
     n = n + v - 1
    Next n
   Else: Cells(a.Row, 9) = a.Cells(1)
   End If
  Next a
  Columns("I:L").HorizontalAlignment = xlCenter
  Columns("I:L").VerticalAlignment = xlCenter
  Application.ScreenUpdating = True
End Sub
Agradeço qualquer ajuda.
Você não está autorizado a ver ou baixar esse anexo.
Por rafael84
Posts
#51086
consegui de uma forma. A quem interessar....
Código: Selecionar todos
Application.DisplayAlerts = False
     With ActiveSheet
        For i = .Cells(.Cells(Rows.Count, 1).End(xlUp).Row, 1).Row To 2 Step -1
 
        If i > 2 Then
            If .Cells(i, 4).Value = .Cells(i - 1, 4).Value And .Cells(i, 4) <> "" Then
               Range(.Cells(i, 4), .Cells(i - 1, 4)).Merge
         'colocar o restante das colunas
               
               End If

         End If
     Next i
     End With
    Application.DisplayAlerts = True
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