Erro de Compilação ...
 
Notifications
Clear all

Erro de Compilação Else sem If

7 Posts
3 Usuários
0 Reactions
1,535 Visualizações
(@fbruzaca)
Posts: 2
New Member
Topic starter
 

Bom dia,

Copiei boa parte de um código, e apliquei a minha planilha, apagando apenas algumas ActiveCell's e incluindo outras.
Eu consegui fazer com que rodasse na planilha q eu tirei o codigo, mas nao consigo na que estou fazendo.

O erro que aparece é Else sem If, e vai direto para uma ActiveCell no VBA mas já verifiquei e parecem estar todos completos.

Alguem sabe onde esta o erro e como resolve-lo?

'somar os respectivos custos
a = Range("c6").Select

soma_sal = 0
soma_desp = 0
soma_imp = 0
soma_alu = 0
soma_esc = 0
soma_ope = 0
soma_tel = 0
soma_frot = 0
soma_terc = 0
soma_ssma = 0
soma_manut = 0
soma_jud = 0
soma_arm = 0
soma_transp = 0
soma_out = 0
soma_dep = 0
soma_recu = 0

Do While ActiveCell.Offset(0, 2) <> ""

If ActiveCell = 7010100 Or ActiveCell = 7010110 Or ActiveCell = 7010120 Or ActiveCell = 7010130 Or ActiveCell = 7010200 Or ActiveCell = 7010210 Or ActiveCell = 7010211 Or ActiveCell = 7010220 Or ActiveCell = 7010310 Or ActiveCell = 7010320 Or ActiveCell = 7010400 Or ActiveCell = 7010500 Or ActiveCell = 7010510 Or ActiveCell = 7010520 Or ActiveCell = 7010600 Or ActiveCell = 7010610 Or ActiveCell = 7010611 Or ActiveCell = 7010620 Or ActiveCell = 7010630 Or ActiveCell = 7010640 Or ActiveCell = 7010642 Or ActiveCell = 7010650 Or ActiveCell = 7010660 Or ActiveCell = 7010820 Or ActiveCell = 7010821 Or ActiveCell = 7010830 Or ActiveCell = 7010901 Or ActiveCell = 7590300 Or ActiveCell = 8060206 Or ActiveCell = 3412000 Or ActiveCell = 3040601001# Or ActiveCell = 3040601002# Or ActiveCell = 3040601003# Or ActiveCell = 3040601004# Or ActiveCell = 3040601005# Or ActiveCell = 3040601006# Or ActiveCell = 3040601007# Or ActiveCell = 3040601008# Or ActiveCell = 3040601009# _
Or ActiveCell = 7010700 Or ActiveCell = 3040601010# Or ActiveCell = 3040601011# Or ActiveCell = 3040601012# Or ActiveCell = 3040601013# Or ActiveCell = 3040601014# Or ActiveCell = 3040602001# Or ActiveCell = 3040602002# Or ActiveCell = 3040602003# Or ActiveCell = 3040602004# Or ActiveCell = 3040602005# Or ActiveCell = 3040602006# Or ActiveCell = 3040602007# Or ActiveCell = 3040602008# Or ActiveCell = 3040602009# Or ActiveCell = 3040602010# Or ActiveCell = 3040602011# Or ActiveCell = 3040602012# Or ActiveCell = 3040602013# Or ActiveCell = 3040602014# Or ActiveCell = 3040602015# Or ActiveCell = 3040603001# Or ActiveCell = 3040603002# Or ActiveCell = 3040603003# Or ActiveCell = 3040603004# Or ActiveCell = 3040603005# Or ActiveCell = 3040603006# Or ActiveCell = 3040603007# Or ActiveCell = 3040603008# Or ActiveCell = 3040604001# Or ActiveCell = 3040604002# Or ActiveCell = 3040604003# Or ActiveCell = 3040604004# Or ActiveCell = 3040605001# Or ActiveCell = 3040605002# Or ActiveCell = 3040605003# _
Or ActiveCell = 3040605004# Or ActiveCell = 3040605005# Or ActiveCell = 3040605006# Or ActiveCell = 3040605007# Or ActiveCell = 3040605008# Or ActiveCell = 3040605009# Or ActiveCell = 3040605010# Or ActiveCell = 3040605011# Or ActiveCell = 3040605012# Or ActiveCell = 3040605013# Or ActiveCell = 3040605014# Or ActiveCell = 3040605015# Or ActiveCell = 3040605016# Or ActiveCell = 3040605017# Or ActiveCell = 3040606001# Or ActiveCell = 3040606002# Or ActiveCell = 3040606003# Or ActiveCell = 3040606004# Or ActiveCell = 3040606005# Or ActiveCell = 3040606006# Or ActiveCell = 3040606007# Or ActiveCell = 3040606008# Or ActiveCell = 3040606009# Or ActiveCell = 3040606010# Or ActiveCell = 3040606011# Or ActiveCell = 3040606012# Or ActiveCell = 3040606013# Or ActiveCell = 3040606014# Or ActiveCell = 3040606015# Or ActiveCell = 3040606016# Or ActiveCell = 3040606017# Or ActiveCell = 3040606019# Or ActiveCell = 8060206 Then b = ActiveCell.Offset(0, 2)

soma_sal = soma_sal + b

ElseIf ActiveCell = 7010801 Or ActiveCell = 7010802 Or ActiveCell = 7010803 Or ActiveCell = 7010805 Or ActiveCell = 7010810 Or ActiveCell = 7010811 Or ActiveCell = 7220370 Or ActiveCell = 7260512 Or ActiveCell = 3040617010# Or ActiveCell = 3040617011# Or ActiveCell = 3040617012# Or ActiveCell = 3040617013# Or ActiveCell = 3040617014# Or ActiveCell = 3040617021# Then b = ActiveCell.Offset(0, 2)
soma_desp = soma_desp + b

ElseIf ActiveCell = 7210101 Or ActiveCell = 7210102 Or ActiveCell = 7210103 Or ActiveCell = 7210104 Or ActiveCell = 7210105 Or ActiveCell = 7210300 Or ActiveCell = 7470100 Or ActiveCell = 7470102 Or ActiveCell = 7470200 Or ActiveCell = 7999120 Or ActiveCell = 7999180 Or ActiveCell = 3040618001# Or ActiveCell = 3040618002# Or ActiveCell = 3040618003# Or ActiveCell = 3040618004# Or ActiveCell = 3040618005# Or ActiveCell = 3040618006# Or ActiveCell = 3040618007# Or ActiveCell = 3040618008# Or ActiveCell = 3040618009# Or ActiveCell = 3040618010# Or ActiveCell = 3040618011# Or ActiveCell = 3040619056# Or ActiveCell = 3060302037# Or ActiveCell = 6220500 Or ActiveCell = 7590809 Or ActiveCell = 7999130 Or ActiveCell = 7999140 Or ActiveCell = 7999150 Or ActiveCell = 7999161 Or ActiveCell = 7999171 Or ActiveCell = 7999180 Or ActiveCell = 7999181 Or ActiveCell = 8210100 Or ActiveCell = 8210400 Or ActiveCell = 8210410 Then b = ActiveCell.Offset(0, 2)
soma_imp = soma_imp + b

ElseIf ActiveCell = 7010621 Or ActiveCell = 7260200 Or ActiveCell = 7260510 Or ActiveCell = 7260511 Or ActiveCell = 7260513 Or ActiveCell = 7260600 Or ActiveCell = 7460100 Or ActiveCell = 7490100 Or ActiveCell = 7590700 Or ActiveCell = 3040616004# Or ActiveCell = 3040616005# Or ActiveCell = 3040616006# Or ActiveCell = 3040616007# Or ActiveCell = 3040616008# Or ActiveCell = 3040616009# Or ActiveCell = 3040616010# Or ActiveCell = 3040616001# Or ActiveCell = 3040616002# Or ActiveCell = 3040616003# Then b = ActiveCell.Offset(0, 2)
soma_alu = soma_alu + b

ElseIf ActiveCell = 7470101 Or ActiveCell = 7480110 Or ActiveCell = 7480120 Or ActiveCell = 7480130 Then b = ActiveCell.Offset(0, 2)
soma_esc = soma_esc + b

ElseIf ActiveCell = 7220330 Or ActiveCell = 7450200 Then b = ActiveCell.Offset(0, 2)
soma_ope = soma_ope + b

ElseIf ActiveCell = 7220310 Or ActiveCell = 7220320 Or ActiveCell = 3040617009# Or ActiveCell = 3040617032# Or ActiveCell = 3040617033# Then b = ActiveCell.Offset(0, 2)
soma_tel = soma_tel + b

ElseIf ActiveCell = 7010140 Or ActiveCell = 7220101 Or ActiveCell = 7220102 Or ActiveCell = 7220103 Or ActiveCell = 7220105 Or ActiveCell = 7260300 Or ActiveCell = 7460300 Or ActiveCell = 7460310 Then b = ActiveCell.Offset(0, 2)
soma_frot = soma_frot + b

ElseIf ActiveCell = 7220171 Or ActiveCell = 7460200 Or ActiveCell = 3040606006# Or ActiveCell = 3040608001# Or ActiveCell = 3040608002# Or ActiveCell = 3040608003# Or ActiveCell = 3040608004# Or ActiveCell = 3040608005# Or ActiveCell = 3040608006# Or ActiveCell = 3040608007# Or ActiveCell = 3040608008# Or ActiveCell = 3040608009# Or ActiveCell = 3040608010# Or ActiveCell = 3040608011# Or ActiveCell = 3040608012# Or ActiveCell = 3040608013# Or ActiveCell = 3040608014# Or ActiveCell = 3040608015# Or ActiveCell = 3040608016# Or ActiveCell = 3040608017# Or ActiveCell = 3040608018# Or ActiveCell = 3040608019# Or ActiveCell = 3040608010# _
Or ActiveCell = 3040608011# Or ActiveCell = 3040608012# Or ActiveCell = 3040608013# Or ActiveCell = 3040608014# Or ActiveCell = 3040608015# Or ActiveCell = 3040608016# Or ActiveCell = 3040608017# Or ActiveCell = 3040608018# Or ActiveCell = 3040608019# Or ActiveCell = 3040608020# Or ActiveCell = 3040608021# Or ActiveCell = 3040608022# Or ActiveCell = 3040608023# Or ActiveCell = 3040608024# Or ActiveCell = 3040608025# Or ActiveCell = 3040608026# Or ActiveCell = 3040608027# Or ActiveCell = 3040608028# Or ActiveCell = 3040608029# Or ActiveCell = 3040608030# Or ActiveCell = 3040608031# Or ActiveCell = 3040608032# Or ActiveCell = 3040608033# Or ActiveCell = 3040608034# Or ActiveCell = 3040608035# Or ActiveCell = 3040608036# Or ActiveCell = 3040608037# Or ActiveCell = 3040608038# Or ActiveCell = 3040608039# Or ActiveCell = 3040608999# Or ActiveCell = 3040615001# Or ActiveCell = 3040615002# Or ActiveCell = 3040615003# Or ActiveCell = 3040615004# Or ActiveCell = 3040615005# _
Or ActiveCell = 3040615006# Or ActiveCell = 3040615007# Or ActiveCell = 3040615008# Or ActiveCell = 3040615009# Or ActiveCell = 3040615010# Or ActiveCell = 3040615011# Or ActiveCell = 3040615012# Or ActiveCell = 3040615013# Or ActiveCell = 3040615014# Or ActiveCell = 3040615015# Or ActiveCell = 3040615016# Or ActiveCell = 3040615017# Or ActiveCell = 3040615018# Or ActiveCell = 3040615019# Or ActiveCell = 3040615020# Or ActiveCell = 3040615021# Or ActiveCell = 3040615022# Or ActiveCell = 8010106010# Or ActiveCell = 8010106110# Then b = ActiveCell.Offset(0, 2)
soma_terc = soma_terc + b

ElseIf ActiveCell = 7210200 Or ActiveCell = 7410401 Or ActiveCell = 7410402 Or ActiveCell = 7410403 Or ActiveCell = 7440400 Then b = ActiveCell.Offset(0, 2)
soma_ssma = soma_ssma + b

ElseIf ActiveCell = 7240300 Or ActiveCell = 7240400 Or ActiveCell = 3040698003# Or ActiveCell = 3040613001# Or ActiveCell = 3040613002# Or ActiveCell = 3040613003# Or ActiveCell = 3040613004# Or ActiveCell = 3040613005# Or ActiveCell = 3040613006# Or ActiveCell = 8010106015# Or ActiveCell = 8010106115# Then b = ActiveCell.Offset(0, 2)
soma_manut = soma_manut + b

ElseIf ActiveCell = 7010800 Or ActiveCell = 7010831 Or ActiveCell = 7250101 Or ActiveCell = 7250102 Or ActiveCell = 7250311 Or ActiveCell = 7250315 Or ActiveCell = 7250319 Or ActiveCell = 7590109 Then b = ActiveCell.Offset(0, 2)
soma_jud = soma_jud + b

ElseIf ActiveCell = 7220360 Or ActiveCell = 7220400 Or ActiveCell = 7240900 Or ActiveCell = 7250300 Or ActiveCell = 7510220 Or ActiveCell = 7985100 Then b = ActiveCell.Offset(0, 2)
soma_arm = soma_arm + b

ElseIf ActiveCell = 7220340 Or ActiveCell = 7220350 Or ActiveCell = 7999400 Or ActiveCell = 7999401 Then b = ActiveCell.Offset(0, 2)
soma_transp = soma_transp + b

ElseIf ActiveCell = 8000100 Or ActiveCell = FV8000120 Or ActiveCell = 3040617001# Or ActiveCell = 3040617002# Or ActiveCell = 3040617003# Or ActiveCell = 3040617004# Or ActiveCell = 3040617005# Or ActiveCell = 3040617006# Or ActiveCell = 3040617007# Or ActiveCell = 3040617008# Or ActiveCell = 3040617015# Or ActiveCell = 3040617016# Or ActiveCell = 3040617018# Or ActiveCell = 3040617019# Or ActiveCell = 3040617020# Or ActiveCell = 3040617022# Or ActiveCell = 3040617023# Or ActiveCell = 3040617024# Or ActiveCell = 3040617025# Or ActiveCell = 3040617027# Or ActiveCell = 3040617028# Or ActiveCell = 3040617031# Or ActiveCell = 3040619001# Or ActiveCell = 3040619002# Or ActiveCell = 3040619003# Or ActiveCell = 3040619004# _
Or ActiveCell = 3040619001# Or ActiveCell = 3040619002# Or ActiveCell = 3040619003# Or ActiveCell = 3040619004# Or ActiveCell = 3040619005# Or ActiveCell = 3040619006# Or ActiveCell = 3040619007# Or ActiveCell = 3040619008# Or ActiveCell = 3040619009# Or ActiveCell = 3040619010# Or ActiveCell = 3040619011# Or ActiveCell = 3040619012# Or ActiveCell = 3040619013# Or ActiveCell = 3040619014# Or ActiveCell = 3040619015# Or ActiveCell = 3040619016# Or ActiveCell = 3040619017# Or ActiveCell = 3040619018# Or ActiveCell = 3040619019# Or ActiveCell = 3040619020# Or ActiveCell = 3040619021# Or ActiveCell = 3040619022# Or ActiveCell = 3040619023# Or ActiveCell = 3040619024# Or ActiveCell = 3040619025# Or ActiveCell = 3040619026# Or ActiveCell = 3040619027# Or ActiveCell = 3040619028# Or ActiveCell = 3040619029# Or ActiveCell = 3040619030# Or ActiveCell = 3040619031# Or ActiveCell = 3040619032# Or ActiveCell = 3040619033# Or ActiveCell = 3040619034# Or ActiveCell = 3040619035# Or ActiveCell = 3040619036# _
Or ActiveCell = 3040619037# Or ActiveCell = 3040619038# Or ActiveCell = 3040619039# Or ActiveCell = 3040619040# Or ActiveCell = 3040619041# Or ActiveCell = 3040619042# Or ActiveCell = 3040619043# Or ActiveCell = 3040619044# Or ActiveCell = 3040619045# Or ActiveCell = 3040619046# Or ActiveCell = 3040619047# Or ActiveCell = 3040619048# Or ActiveCell = 3040619049# Or ActiveCell = 3040619050# Or ActiveCell = 3040619055# Or ActiveCell = 3040619057# Or ActiveCell = 3040619058# Or ActiveCell = 3040619060# Or ActiveCell = 3040620001# Or ActiveCell = 3040620002# _
Or ActiveCell = 3040620003# Or ActiveCell = 3040620004# Or ActiveCell = 3040620005# Or ActiveCell = 3040620006# Or ActiveCell = 3040620007# Or ActiveCell = 3040620008# Or ActiveCell = 3040620009# Or ActiveCell = 3040620010# Or ActiveCell = 3040620011# Or ActiveCell = 3040620012# Or ActiveCell = 3040620013# Or ActiveCell = 3040620014# Or ActiveCell = 3040620015# Or ActiveCell = 3040620016# Or ActiveCell = 3040620017# Or ActiveCell = 3040620018# Or ActiveCell = 3040620019# Or ActiveCell = 3040620022# Or ActiveCell = 3040620023# Or ActiveCell = 3040620024# Or ActiveCell = 3040620025# Or ActiveCell = 3040620026# Or ActiveCell = 3040620027# Or ActiveCell = 3040620028# Or ActiveCell = 3040620029# Or ActiveCell = 3040620030# Or ActiveCell = 3040620031# Or ActiveCell = 3040620032# Or ActiveCell = 3040620033# Or ActiveCell = 3040620034# Or ActiveCell = 3040620035# Or ActiveCell = 3040620036# Or ActiveCell = 3040620037# Or ActiveCell = 3040620038# _
Or ActiveCell = 3040620039# Or ActiveCell = 3040620040# Or ActiveCell = 3040620041# Or ActiveCell = 3040620042# Or ActiveCell = 3040620043# Or ActiveCell = 3040620100# Or ActiveCell = 3040620101# Or ActiveCell = 3040620102# Or ActiveCell = 3040620103# Or ActiveCell = 3040620104# Or ActiveCell = 3040620105# Or ActiveCell = 3040650001# Or ActiveCell = 3040650002# Or ActiveCell = 3040650003# Or ActiveCell = 3040651001# Or ActiveCell = 3040651003# Or ActiveCell = 3040698001# Or ActiveCell = 3040698002# Or ActiveCell = 3040698005# Or ActiveCell = 3040800000# Or ActiveCell = 3040900000# Or ActiveCell = 3041000000# Or ActiveCell = 3049999001# Or ActiveCell = 3049999002# Or ActiveCell = 3049999003# Or ActiveCell = 3049999989# Or ActiveCell = 3049999991# Or ActiveCell = 3049999995# Or ActiveCell = 3049999996# Or ActiveCell = 3049999997# Or ActiveCell = 3049999998# Or ActiveCell = 3070101001# Or ActiveCell = 3070101004# Or ActiveCell = 3070101005# Or ActiveCell = 3499999999# _
Or ActiveCell = 8010101000# Or ActiveCell = 8010101001# Or ActiveCell = 8010101002# Or ActiveCell = 8010101003# Or ActiveCell = 8010101010# Or ActiveCell = 8010101015# Or ActiveCell = 8010101016# Or ActiveCell = 8010101020# Or ActiveCell = 8010101025# Or ActiveCell = 8010101030# Or ActiveCell = 8010101031# Or ActiveCell = 8010101035# Or ActiveCell = 8010101040# Or ActiveCell = 8010101045# Or ActiveCell = 8010101060# Or ActiveCell = 8010101085# Or ActiveCell = 8010101090# Or ActiveCell = 8010101099# Or ActiveCell = 8010101100# Or ActiveCell = 3010100000# Or ActiveCell = 3010200000# Or ActiveCell = 3010300000# Or ActiveCell = 3010400000# Or ActiveCell = 3010500000# Or ActiveCell = 3010600000# Or ActiveCell = 3020100000# Or ActiveCell = 3020200000# Or ActiveCell = 3020300000# Or ActiveCell = 3020400000# Or ActiveCell = 3020500000# Or ActiveCell = 3020600000# _
Or ActiveCell = 3020700000# Or ActiveCell = 3020800000# Or ActiveCell = 3020900000# Or ActiveCell = 3021000000# Or ActiveCell = 3021100000# Or ActiveCell = 3021200000# Or ActiveCell = 3021300000# Or ActiveCell = 3021300001# Or ActiveCell = 3021400000# Or ActiveCell = 3021500000# Or ActiveCell = 3021600000# Or ActiveCell = 3021700000# Or ActiveCell = 3021800000# Or ActiveCell = 3021900000# Or ActiveCell = 3022000000# Or ActiveCell = 3040300000# Or ActiveCell = 3040400000# Or ActiveCell = 3040600000# Or ActiveCell = 3040607001# _
Or ActiveCell = 3040607002# Or ActiveCell = 3040607003# Or ActiveCell = 3040607004# Or ActiveCell = 3040607005# Or ActiveCell = 3040607006# Or ActiveCell = 3040607007# Or ActiveCell = 3040607008# Or ActiveCell = 3040607009# Or ActiveCell = 3040607010# Or ActiveCell = 3040607011# Or ActiveCell = 3040607012# Or ActiveCell = 3040607013# Or ActiveCell = 3040607014# Or ActiveCell = 3040607015# Or ActiveCell = 3040607016# Or ActiveCell = 3040607017# Or ActiveCell = 3040607018# _
Or ActiveCell = 3040607090# Or ActiveCell = 3040607096# Or ActiveCell = 3040607097# Or ActiveCell = 3040607098# Or ActiveCell = 3040607099# Or ActiveCell = 3040609001# Or ActiveCell = 3040609002# Or ActiveCell = 3040609003# Or ActiveCell = 3040609004# Or ActiveCell = 3040609005# Or ActiveCell = 3040609006# Or ActiveCell = 3040609007# Or ActiveCell = 3040609999# Or ActiveCell = 3040610001# Or ActiveCell = 3040610002# Or ActiveCell = 3040610003# Or ActiveCell = 3040611001# Or ActiveCell = 3040611002# Or ActiveCell = 3040612001# Or ActiveCell = 3040612002# Or ActiveCell = 3040612003# Or ActiveCell = 3040612004# Or ActiveCell = 3040614001# Or ActiveCell = 8010101105# Or ActiveCell = 8010101110# Or ActiveCell = 8010101115# Or ActiveCell = 8010101120# Or ActiveCell = 8010101125# Or ActiveCell = 8010101130# Or ActiveCell = 8010101135# Or ActiveCell = 8010101220# Or ActiveCell = 8010101500# _
Or ActiveCell = 8010103005# Or ActiveCell = 8010103010# Or ActiveCell = 8010103015# Or ActiveCell = 8010103020# Or ActiveCell = 8010103025# Or ActiveCell = 8010103030# Or ActiveCell = 8010103035# Or ActiveCell = 8010103040# Or ActiveCell = 8010103045# Or ActiveCell = 8010103050# Or ActiveCell = 8010104005# Or ActiveCell = 8010104010# Or ActiveCell = 8010104015# Or ActiveCell = 8010104020# Or ActiveCell = 8010104025# Or ActiveCell = 8010104030# Or ActiveCell = 8010104035# Or ActiveCell = 8010104040# Or ActiveCell = 8010104045# Or ActiveCell = 8010104050# Or ActiveCell = 8010104070# Or ActiveCell = 8010106005# Or ActiveCell = 8010106105# Or ActiveCell = 8010201005# Or ActiveCell = 8010201010# Or ActiveCell = 8010201015# Or ActiveCell = 8010202005# Or ActiveCell = 8010203005# Or ActiveCell = 89999999999# Then b = ActiveCell.Offset(0, 2)
soma_out = soma_out + b

ElseIf ActiveCell = 8210200 Then b = ActiveCell.Offset(0, 2)
soma_dep = soma_dep + b

ElseIf ActiveCell = 6900205 Or ActiveCell = 8399203 Then b = ActiveCell.Offset(0, 2)
soma_recu = soma_recu + b

End If

a = ActiveCell.Offset(1, 0).Select

Loop

 
Postado : 20/05/2015 9:48 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Não tenho certeza, mas pode ser o tamanho dos "if /or"; apenas o primeiro há mais de 100 variáveis; o que torna dificil sua utilização/manutenção.
Sugiro montar/listar as variantes em uma planilha de apoio;assim a visualização se torna mais clean e de facil manutenção; e montar o codigo "procurando" nessas areas
Supondo que a primeira leva do if esteja em plan1 range A2:A200 (as demais em outras colunas adjacentes)
o if ficará ]+/- assim:

If VBA.IsNumeric(Application.Match(activecell.Value, Sheets("plan1").Range("A2:A200"), 0)) then 
soma_arm = soma_arm + ActiveCell.Offset(0, 2)
elseif.........

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 20/05/2015 11:00 am
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Sinceramente, tenho duas coisas pra dizer:
1) esse é o código mais feio que eu já vi, e neste caso, a feiura do código o está atrapalhando
2) pense em usar recursos do próprio Excel como PROCV() (application.worksheetfunction.vlookup(), ou dicionário, ou matriz com contadores, vc reduzirá não só o tamanho do código como a facilidade de manutenção.

O código diz que falta um End If... e isso é difícil encontrar ou saber aonde ele deveria estar, com tantas condições....

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 20/05/2015 11:11 am
(@edcronos)
Posts: 1006
Noble Member
 

só não vou falar que é o pior pq deve ter muito mostro feio aí pelo submundo do excel :P

mas bem, pelo que vi vc quer saber se a celula ativa é algum do codigos
ActiveCell = 3020900000# Or ActiveCell = 3021000000

existe varias maneiras de fazer isso
codigos =Split( "3020900000#,3021000000,..." ",")

for n=0 to ubound(codigos,1)
if codigos(n)=ActiveCell then...
next
...
ou então crie uma lista de codigos na propria planilha e adicione em um array e faça a mesma coisa, assim fica mais facil e vc pode adicionar ou mudar os codigos de acordo com a necessidade sem mexer na macro

como falei, existe muitas maneiras de fazer oq vc quer

o ideal seria postar um exemplo do seu arquivo, e explicar oq vc quer fazer

Somente é impossíveis até que alguém faça
A logica está presa na irracionalidade humana, e morta nos que se consideram donos da verdade.

"ALGUM MODERADOR ME EXPULSE DO FÓRUM POR FAVOR"

 
Postado : 20/05/2015 12:13 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Se for postar seu arquivo, elimine o excesso de dados e compacte-o.

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 20/05/2015 1:08 pm
(@fbruzaca)
Posts: 2
New Member
Topic starter
 

Prezados, o problema é o seguinte:

Estou puxando os dados de uma planilha para outra automaticamente. O código é o Do While If ActiveCell = ..., inserindo algumas condições, mas ele não puxa todas as condições.

A condição é um numero de conta (e são várias Contas), e a macro deve puxar o valor dessas contas, que está à duas células de distancia.

O problema é que ele puxa, por exemplo, a conta 7010400, mas não a 7010401, que devem ser somadas.

Alguem tem alguma sugestao sobre o q pode estar acontecendo?

Em anexo esta o codigo por inteiro.

fbruzaca, não abra novos tópicos do mesmo assunto quando já tem um em aberto, e tambem veja as regras referente a anexos.
Arquivo Anexo Deletado

Motivo :
Os anexos tem de estar compactados conforme as regras do Forum: - viewtopic.php?f=7&t=203
• Upload
Devido a ultrapassagem da marca de 1,5Gb de armazenamento de arquivos na hospedagem do Planilhando,
limitaremos o tamanho de cada arquivo para 2Mb sendo obrigatório o uso dos formatos .zip - .rar - .ice visto
a gratuidade e não geração de recursos para bancar o site.

Grato pela compreensão.

[]s Mauro Coutinho
Administrador

 
Postado : 22/05/2015 2:37 pm
Fernando Fernandes
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Eu acho que o problema pode estar e todas as vezes que vc usou o Then

vc tem código logo à direita dele, e depois uma linha de comando embaixo...
Faça isso, abra o excel, entre no vbe, crie um módulo em branco e cole isso:

Sub Teste()

If x Then a = a
    b = b
ElseIf y Then c = c
    d = d
End If

End Sub

Veja que é exatamente o que você fez em todas as suas condições. Se vc tentar rodar isso, o erro será o mesmo. Else sem If. Pq?
Pq quando vc disse
If x Then a = a
Vc fechou a condicional. Agora o Else ficou sem dono. E consequentemente b=b vai rodar sempre pois ele não é regido a condição acima, que já acabou.

Para corrigir, o correto seria:

Sub Teste()

If x Then 
    a = a
    b = b
ElseIf y Then 
    c = c
    d = d
End If

End Sub

Ficou claro? Isso vai resolver seu problema com o Else sem If, ou seja, Else sem dono, perdido no código. Mas não posso garantir que essa geringonça funcione!

Abs,

FF

Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel

 
Postado : 10/06/2015 9:14 pm