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
#69047
Olá

Tentando reproduzir no excel o que foi explicado em um video para automatizar a extração de informações de outras planilhas,( planilha Aula, importar dados das planilhas "Campus"),
E não funcionou como explicado, quando dou F8 no vba, executa bem até a abrir outras planilha, mas a busca das informações não funcionou, e também adicionei um botão para importar e está dando Erro "em tempo de execução '424'"


Sub Importar_Dados()

On Error GoTo Erro

Application.ScreenUpdating = False


Dim Guia As Object
Dim Planilha As Workbook
Dim EnderecoPlan As String
Dim Coluna As Double, Linha As Double, ColDestino As Double
Dim ColInicial As Double, ColFinal As Double, LinOrigem As Double


EnderecoPlan = Application.GetOpenFilename(FileFilter:="file, *.xls*")


If EnderecoPlan <> Empty And EnderecoPlan <> "Falso" Then
Set Planilha = Application.Workbooks.Open(EnderecoPlan)
Else
Application.ScreenUpdating = True
Exit Sub
End If

Set Guia = Planilha.Worksheets(1)

Windows(Planilha.Name).Visible = False

Coluna = 1
Lin = 1


Inicio:
Do

Linha = Linha + 1

If Guia.Cells(Linha, Coluna).Value <> Empty Then
LinOrigem = Linha
ColInicial = Coluna


Do
Coluna = Coluna + 1
Loop Until Guia.Cells(Linha, Coluna).Value = Empty

ColFinal = Coluna - 1
Exit Do
End If

If Coluna = 100 Then
MsgBox "Não encontrado cabeçalho!", vbExclamation, "IMPORTAR"
Exit Sub
End If




Loop Until Linha = 10

If LinOrigem = Empty Then
Coluna = Coluna + 1
Linha = 1
GoTo Inicio:

End If

Coluna = ColIncial
ColDestino = 2
Linha = WorksheetFunction.CountA(Planilha1.Range("B:B")) + 3

With Planilha1

Do
LinOrigem = LinOrigem + 1

For Coluna = ColInicial To ColFinal
.Cells(Linha, ColDestino).Value = Guia.Cells(LinOrigem, Coluna).Value
ColDestino = ColDestino + 1
Next Coluna

ColDestino = 2
Linha = Linha + 1


Loop Until Guia.Cells(LinOrigem, ColInicial).Value = Empty

End With

Windows(Planilha.Name).Visible = True

Application.DisplayAlerts = False
Windows(Planilha.Name).Close
Application.DisplayAlerts = True


Set Planiha = Nothing
Set Guia = Nothing

Application.ScreenUpdating = True


Exit Sub
Erro:
MsgBox "Erro!", vbCritical, "IMPORTAR"

End Sub



Do botão

Private Sub CommandButton1_Click()
Módulo2.Importar_Dados
End Sub


Grato
Você não está autorizado a ver ou baixar esse anexo.
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