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 alanisfcsm
Posts
#8908
Boa tarde.
Preciso que o botão de opção esteja na planilha "A", mas a execução em vba seja na planilha "B".
Estou meio perdido aqui.
Grato.



Sub EMPRESA01()
'
' empresa01
'

'
Range("B19:I22").Select
Selection.ClearContents
Range("B25:I28").Select
Selection.Copy
Range("B19:I22").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B18").Select
End Sub




Sub EMPRESA02()
'
' empresa02
'

'
Range("B19:I22").Select
Selection.ClearContents
Range("B31:I34").Select
Selection.Copy
Range("B19:I22").Select
ActiveSheet.Paste
Application.CutCopyMode = False
Range("B18").Select
End Sub
Editado pela última vez por alanisfcsm em 22 Mar 2016 às 15:24, em um total de 1 vez.
Por alanisfcsm
Posts
#8912
Obrigado Jonathaluis
Esqueci de dizer que o botão é de opção, desculpe.
O comando descrito por você funciona, mas ele muda de planilha. gostaria que a visualização permanecesse na planilha "A", tem como?
Por alanisfcsm
Posts
#8913
Jonathaluis escreveu:Boa tarde!

Primeiro comando antes de todos os restantes:

Worksheets("Plan2").Select

Obrigado Jonathaluis
Esqueci de dizer que o botão é de opção, desculpe.
O comando descrito por você funciona, mas ele muda de planilha. gostaria que a visualização permanecesse na planilha "A", tem como?
Resposta Rápida
Resposta
Avatar do usuário
Por Jonathaluis
Posts Avatar
#8914
Alanisfcsm,

Vê se atende sua necessidade:

Sub EMPRESA01()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(25, 2), A.Cells(28, 9))

End Sub

Sub EMPRESA02()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(31, 2), A.Cells(34, 9))

End Sub
Avatar do usuário
Por Jonathaluis
Posts Avatar
#8915
Alanisfcsm,

Faltou um detalhe, o value, se não ele não copia o valor, e agora com descrição das funções:

Sub EMPRESA01()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents 'Limpa o range da coluna B19 até I22
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(25, 2), A.Cells(28, 9)).value 'Copia o conteúdo do Range B25 até o I28 para B19 até B22

End Sub

Sub EMPRESA02()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents 'Limpa o range da coluna B19 até I22
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(31, 2), A.Cells(34, 9)).value 'Copia o conteúdo do Range B31 até o I34 para B19 até B22

End Sub
Por alanisfcsm
Posts
#8916
Jonathaluis escreveu:Alanisfcsm,

Vê se atende sua necessidade:

Sub EMPRESA01()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(25, 2), A.Cells(28, 9))

End Sub

Sub EMPRESA02()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(31, 2), A.Cells(34, 9))

End Sub

Funcionou! :D
Obrigado Jonathaluis!
Valeu mesmo!
Por alanisfcsm
Posts
#8917
alanisfcsm escreveu:
Jonathaluis escreveu:Alanisfcsm,

Vê se atende sua necessidade:

Sub EMPRESA01()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(25, 2), A.Cells(28, 9))

End Sub

Sub EMPRESA02()

Dim A As Worksheet 'Plan 2
Set A = Worksheets("Plan2") 'A representa planilha 2

A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents
A.Range(A.Cells(19, 2), A.Cells(22, 9)) = A.Range(A.Cells(31, 2), A.Cells(34, 9))

End Sub

Funcionou! :D
Obrigado Jonathaluis!
Valeu mesmo!
Cara, você é rápido!
Não sabia que poderia fazer assim (A.Range(A.Cells(19, 2), A.Cells(22, 9)).ClearContents )
Muito obrigado!
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