Respostas criadas no fórum
-
AutorArtigos
-
jorgerod
Administradorjorgerod
Administradorboas,
efectuaste o debug do teu código? mostra alguma linha onde poderá estar o erro?
sabes, é bastante difíclil verificar o potencial erro, perante a quantidade de código que apresentas.
achas que podes anexar a planilha, para podermos ver melhor o que eventualmente pode estar a provocar o erro, ou é privada e não podes?
diz qualquer coisa, ok?
jorgerod
Administradorboas,
aproveitando o que se encontra no anexo, talvez juntar as duas fórmulas num só segmento de código:
{=Índice($a$1:$e$100;corresp(mÍnimo(se($b$2:$b$100=h2;$d$2:$d$100));$d$2:$d$100;0)+1;5)}
como foi dito e bem, tem que ser como matriz, ou seja com as {}, conseguidas através das teclas ctrl + shift + enter.
jorgerod
Administradorolá dina,
uma maneira simples, entre outras possíveis:
por exemplo, em e11: =a5&”/”&b5
em e12: =deslocamento(a5;1;0) &”/”&deslocamento(b5;1;0)
copias de e12 até e14
depois fazes o seguinte:
marcas de e12:e14 e fazes ctrl + c
depois, vais para a célula para onde pretendes iniciar, por exemplo e20. aí, fazes colar especial:
escolhes: colar: valores; operação: nenhuma; e marcas transpor. dás ok.
se tudo correr bem, terás o que pretendes entre e20 e h20.
diz qq coisa, ok?
fica bem.
jorgerod
Administradorwagner,
eu continuo a utilizar o windows 7 pro, de 32 bits e o office 2010 pro, também de 32 bits…
de qualquer modo, o pouco que vi sobre este assunto, pode ser visto, em: http://br.groups.yahoo.com/group/excelbr/message/76357
no entanto, a microsoft, deu uma resposta mais simples, que pode ser vista em:
http://support.microsoft.com/kb/983043jorgerod
Administradorboas, wagner,
com o inputbox normal, não é possível fazer o que pretendes.
no entanto, há a possibilidade de simular um inputbox, através de código, que parece mesmo o inputbox original. se colocares o código para onde te direccionarei de seguida, no teu código, em vez de digitares , digitarás …
o link onde o código fonte se encontra e que é mérito do mvp daniel klan, é o seguinte:
http://www.tomasvasquez.com.br/blog/microsoft-office/vba-utilizando-inputbox-com-mascara-senha
fica bem.
jorgerod
Administradorboas, wagner!!
talvez qualquer coisa, como:
sub proteger()
application.screenupdating = false
sbdesproteger = “digite uma senha para proteger o arquivo.” & vbcrlf _
sbtitulo = “wagner goularte”
for each wsplan in activeworkbook.worksheets
if wsplan.protectcontents = true then
msgbox “arquivo já está protegido!!!” & vbcrlf _
, vbcritical, “wagner goularte”
exit sub
end if
next wsplansbproteger = application.inputbox(prompt:=sbdesproteger, title:=sbtitulo, default:=””, type:=2)
if sbproteger = ok then
if sbproteger = “” then
msgbox “digite uma senha !!!”
sbproteger = application.inputbox(prompt:=sbdesproteger, title:=sbtitulo, default:=””, type:=2)
end if
elseif sbproteger = cancel then
exit sub
end ifif sbproteger = vbcancel then
msgbox “arquivo não foi protegido!!!” & vbcrlf _
, vbcritical, “wagner goularte”
exit sub
end iffor each wsplan in activeworkbook.worksheets
wsplan.protect password:=sbproteger, drawingobjects:=true, contents:=true, scenarios:=true, _
allowfiltering:=true, allowformattingcells:=true, allowformattingcolumns:=true, _
allowformattingrows:=true, allowinsertingcolumns:=true, allowinsertingrows:=true, _
allowinsertinghyperlinks:=true, allowdeletingcolumns:=true, allowdeletingrows:=true, _
allowsorting:=true, allowusingpivottables:=truenext wsplan
msgbox “arquivo protegido com sucesso!!!”
sbproteger = empty
application.screenupdating = true
end if
end subdiz alguma coisa, ok?
fica bem!!!
jorgerod
Administradorboas,
para o que pretendes, podes utilizar uma função personalizada, criada pelo , denominada stringconcat().
por exemplo, para a coluna relacionada com os recebimentos, na planilha fluxo de caixa, podes criar a seguinte fórmula:
em f5: {=stringconcat(“|”;se(‘contas a receber’!$g$4:$g$20=a5;’contas a receber’!$h$4:$h$20;””))}
: o exemplo tem como fontes g4 a g20 e h4 a h20, mas, é claro, os ranges terão a dimensão que se pretender)
como é um array, as chavetas são provenientes do conjunto de teclas ctrl + shift + enter.
copias a fórmula de f5, para baixo na coluna f, até onde pretenderes.
para a coluna relacionada com os pagamentos, podes criar a seguinte fórmula:
em g5: {=stringconcat(“|”;se(‘contas a pagar’!$g$4:$g$20=a5;’contas a pagar’!$h$4:$h$20;””))}
: o exemplo tem como fontes g4 a g20 e h4 a h20, mas, é claro, os ranges terão a dimensão que se pretender)
como é um array, as chavetas são provenientes do conjunto de teclas ctrl + shift + enter.
copias a fórmula de g5, para baixo na coluna g, até onde pretenderes.
agora e como parte inicial, deves criar um módulo vba, onde colocarás o seguinte código, repito, do , o qual tem todo o mérito:
function stringconcat(sep as string, paramarray args()) as variant
””””””””””””””””””””””””””””””””””””
‘ stringconcat
‘ by chip pearson, chip@cpearson.com, http://www.cpearson.com
‘ http://www.cpearson.com/excel/stringconcatenation.aspx
‘ this function concatenates all the elements in the args array,
‘ delimited by the sep character, into a single string. this function
‘ can be used in an array formula. there is a vba imposed limit that
‘ a string in a passed in array (e.g., calling this function from
‘ an array formula in a worksheet cell) must be less than 256 characters.
‘ see the comments at string too long handling for details.
””””””””””””””””””””””””””””””””””””
dim s as string
dim n as long
dim m as long
dim r as range
dim numdims as long
dim lb as long
dim isarrayalloc as boolean”””””””””””””””””””””’
‘ if no parameters were passed in, return
‘ vbnullstring.
”””””””””””””””””””””’
if ubound(args) – lbound(args) + 1 = 0 then
stringconcat = vbnullstring
exit function
end iffor n = lbound(args) to ubound(args)
””””””””””””””””””””””””
‘ loop through the args
””””””””””””””””””””””””
if isobject(args(n)) = true then
””””””””””””””””””’
‘ object
‘ if we have an object, ensure it
‘ it a range. the range object
‘ is the only type of object we’ll
‘ work with. anything else causes
‘ a #value error.
””””””””””””””””””
if typeof args(n) is excel.range then
””””””””””””””””””””’
‘ if it is a range, loop through the
‘ cells and create append the elements
‘ to the string s.
””””””””””””””””””””’
for each r in args(n).cells
if len(r.text) > 0 then
s = s & r.text & sep
end if
next r
else
””””””””””””””””’
‘ unsupported object type. return
‘ a #value error.
””””””””””””””””’
stringconcat = cverr(xlerrvalue)
exit function
end ifelseif isarray(args(n)) = true then
””””””””””””””””””’
‘ array
‘ if args(n) is an array, ensure it
‘ is an allocated array.
””””””””””””””””””’
isarrayalloc = (not iserror(lbound(args(n))) and _
(lbound(args(n)) <= ubound(args(n))))
if isarrayalloc = true then
''''''''''''''''''''''''''''''''''''
' the array is allocated. determine
' the number of dimensions of the
' array.
'''''''''''''''''''''''''''''''''''''
numdims = 1
on error resume next
err.clear
numdims = 1
do until err.number 0
lb = lbound(args(n), numdims)
if err.number = 0 then
numdims = numdims + 1
else
numdims = numdims – 1
end if
loop
on error goto 0
err.clear
”””””””””””””””””
‘ the array must have either
‘ one or two dimensions. greater
‘ that two caues a #value error.
”””””””””””””””””
if numdims > 2 then
stringconcat = cverr(xlerrvalue)
exit function
end if
if numdims = 1 then
for m = lbound(args(n)) to ubound(args(n))
if args(n)(m) vbnullstring then
s = s & args(n)(m) & sep
end if
next melse
””””””””””””””””””””””””
‘ string too long handling
‘ here, the error handler must be set to either
‘ on error goto continueloop
‘ or
‘ on error goto errh
‘ if you use errh, then any error, including
‘ a string too long error, will cause the function
‘ to return #value and quit. if you use continueloop,
‘ the problematic value is ignored and not included
‘ in the result, and the result is the concatenation
‘ of all non-error values in the input. this code is
‘ used in the case that an input string is longer than
‘ 255 characters.
””””””””””””””””””””””””
on error goto continueloop
‘on error goto errh
err.clear
for m = lbound(args(n), 1) to ubound(args(n), 1)
if args(n)(m, 1) vbnullstring then
s = s & args(n)(m, 1) & sep
end if
next m
err.clear
m = lbound(args(n), 2)
if err.number = 0 then
for m = lbound(args(n), 2) to ubound(args(n), 2)
if args(n)(m, 2) vbnullstring then
s = s & args(n)(m, 2) & sep
end if
next m
end if
on error goto errh:
end if
else
if args(n) vbnullstring then
s = s & args(n) & sep
end if
end if
else
on error resume next
if args(n) vbnullstring then
s = s & args(n) & sep
end if
on error goto 0
end if
continueloop:
next n””””””””””””””’
‘ remove the trailing sep
””””””””””””””’
if len(sep) > 0 then
if len(s) > 0 then
s = left(s, len(s) – len(sep))
end if
end ifstringconcat = s
””””””””””””””’
‘ success. get out.
””””””””””””””’
exit function
errh:
””””””””””””””’
‘ error. return #value
””””””””””””””’
stringconcat = cverr(xlerrvalue)
end functionjorgerod
Administradorwagner,
vê o exemplo que construi, para o exercício. experimentei e, como está, não fecha os outros ficheiros, só o que tem a cláusla restritiva, como, acho, que pretendes.
Wagner_2011-10-14.zipjorgerod
Administradorwagner,
o evento workbook_beforeclose, se tiver o cancel=true, não só não dá para fechar com o “x”, como também não dá para fechar de outra forma.
penso que a melhor maneira de o fazer, será utilizando, por exemplo, o seguinte código num módulo:
public vflag as boolean
sub sair()
vflag = true
application.quit
thisworkbook.close savechanges:=trueend sub
depois, crias dois eventos no próprio livro, um ao abrir, que vai dizer que a variável vflag=false, para não deixar fechar com o “x” e o outro evento, antes de fechar, que vai verificar se a variável está como true ou como false. ora, neste caso, estará como true, apenas se executares o sub sair, caso contrário, continuará como false e, deste modo, não deixa fechar.
private sub workbook_beforeclose(cancel as boolean)
if vflag = true then
else
msgbox “favor clicar no botão ‘sair’ !!!”
cancel = true
end ifend sub
private sub workbook_open()
vflag = false
end subverifica e depois diz qualquer coisa, ok?
fica bem.
jorgerod
Administradorwagner,
tenta adaptar de: http://en.allexperts.com/q/excel-1059/2009/1/disable-x-close-button.htm
jorgerod
Administradorolá dina,
verifica agora.
recordo que, para além de não ter testado ao limite, os exemplos servem para ajudar a resolver os problemas, devendo ser adaptados na medida do possível.
diz qq coisa, ok?
CpiadeDina_Silva_10-10-2011_2011-10-11.xlsxjorgerod
Administradorolá dina,
embora não tenha sido muito testado, em anexo envio ficheiro que contém algumas dicas sobre como, talvez, conseguir resolver o problema que indicaste.
espero que percebas o que contêm as fórmulas. tentei fazer por etapas, para ficar mais perceptível.
diz qualquer coisa, ok?
jorgerod
Administradorwagner,
talvez:
private sub workbook_beforeclose(cancel as boolean)
cancel = true
end subjorgerod
Administradorboas, wagner,
experimenta ver e adaptar a partir de: http://www.vbaexpress.com/kb/getarticle.php?kb_id=468
talvez te ajude.
-
AutorArtigos
EXCELer Tudo sobre EXCEL em Português