Respostas criadas no fórum
-
AutorArtigos
-
jorgerod
AdministradorÉ sempre óptima a partilha de informação, porque nos ajuda a criar condições de solução para os nossos problemas e há sempre partes de código que podem ser aproveitadas para outro tipo de soluções.
obrigado em nome do forum do exceler! 🙂
jorgerod
Administradorboas, francordeiro,
experimenta adaptar, a partir do seguinte código que colhi do site vba express, cujo mérito lhe está associado:
‘code to be placed in the worksheet(s) you want to use this in
option explicit
public oldrange as rangeprivate sub worksheet_selectionchange(byval target as excel.range)
on error resume next
dim rng as range
set rng = target(1, 1)oldrange.comment.visible = false
with rng
if not .comment is nothing then
if .comment.visible = false then
.comment.visible = true
else
.comment.visible = false
end if
end if
end withset oldrange = target(1, 1)
end subprivate sub worksheet_beforedoubleclick(byval target as excel.range, cancel as boolean)
on error resume next
dim cmttext as string
dim inputtext as stringif target.comment is nothing then
cmttext = inputbox(“enter info:”, “comment info”)
if cmttext = “” then exit sub
target.addcomment text:=cmttext
target.comment.visible = true
target.comment.shape.textframe.autosize = true ‘remove if you want to size it yourself
else
if target.comment.text “” then
inputtext = inputbox(“enter info:”, “comment info”)
if inputtext = “” then exit sub
cmttext = target.comment.text & chr(10) & inputtext
else
cmttext = inputbox(“enter info:”, “comment info”)
end if
target.clearcomments
target.addcomment text:=cmttext
target.comment.visible = true
target.comment.shape.textframe.autosize = true ‘remove if you want to size it yourself
end ifcancel = true ‘remove this if you want to enter text in the cell after you add the comment
end subao dares um duplo click na célula pretendida, adicionarás o comentário que pretendes. se deres novamente um duplo click na mesma célula, irás acrescentar um novo comentário, mantendo-se os comentários anteriores.
jorgerod
Administradorboas, patropi,
tentando responder à tua questão:
a solução poderá passar por duas vias:
1º – validação de dados, como fizeste, para não permitir inserção de valor superior ao pretendido;
2º – código vba, de modo a não permitir que possa inserir-se valor em mais de uma célula.
aqui vai o prototipo de código vba, para ser melhorado, claro:
private sub worksheet_change(byval target as range)
if target.cells.count > 1 then exit sub
if intersect(target, range(“g10:i10”)) is nothing then exit sub
application.enableevents = false
activesheet.unprotect‘se g10 tiver valor fecha h10
if target.column = 7 and isempty(target) = false then
activesheet.cells(target.row, target.column + 1).locked = true
end if‘se g10 tiver valor fecha i10
if target.column = 7 and isempty(target) = false then
activesheet.cells(target.row, target.column + 2).locked = true
end if‘se g10 não tiver valor abre h10
if target.column = 7 and isempty(target) = true then
activesheet.cells(target.row, target.column + 1).locked = false
end if‘se g10 não tiver valor abre i10
if target.column = 7 and isempty(target) = true then
activesheet.cells(target.row, target.column + 2).locked = false
end if‘se h10 tiver valor fecha g10
if target.column = 8 and isempty(target) = false then
activesheet.cells(target.row, target.column – 1).locked = true
end if‘se h10 tiver valor fecha i10
if target.column = 8 and isempty(target) = false then
activesheet.cells(target.row, target.column + 1).locked = true
end if‘se h10 não tiver valor abre g10
if target.column = 8 and isempty(target) = true then
activesheet.cells(target.row, target.column – 1).locked = false
end if‘se h10 não tiver valor abre i10
if target.column = 8 and isempty(target) = true then
activesheet.cells(target.row, target.column + 1).locked = false
end if‘se i10 tiver valor fecha h10
if target.column = 9 and isempty(target) = false then
activesheet.cells(target.row, target.column – 1).locked = true
end if‘se i10 tiver valor fecha g10
if target.column = 9 and isempty(target) = false then
activesheet.cells(target.row, target.column – 2).locked = true
end if‘se i10 não tiver valor abre h10
if target.column = 9 and isempty(target) = true then
activesheet.cells(target.row, target.column – 1).locked = false
end if‘se i10 não tiver valor abre g10
if target.column = 9 and isempty(target) = true then
activesheet.cells(target.row, target.column – 2).locked = false
end ifapplication.enableevents = true
activesheet.protectend sub
fica bem e diz qq coisa, ok?
jorgerod
Administradoracho que, no teu exemplo, o range que está a ser copiado, é o range abaixo do range pretendido. no entanto, o código está óptimo, só precisa de alguns pequenos acertos! 🙂
fica bem.
jorgerod
Administradoralbino,
uma outra alternativa possível, para melhorares e adaptares:
private sub worksheet_change(byval target as range)
dim rngdest as rangeapplication.cutcopymode = true
application.screenupdating = falsesheets(“folha2”).range(“a1:f100”).delete
sheets(“folha1”).select
finalrow = cells(rows.count, 1).end(xlup).row
for x = 1 to finalrow
thisvalue = cells(x, 7).value
if thisvalue = 1 then
sheets(“folha1”).range(cells(x, 1), cells(x, 6)).select
selection.copyset rngdest = worksheets(“folha2”). _
range(“a” & cstr(application.rows.count)).end(xlup).offset(1)selection.copy destination:=rngdest
else
end if
next x
application.cutcopymode = false
application.screenupdating = true
end subfica bem e diz qq coisa, ok?
jorgerod
Administradornão podes enviar com o formato .xls ou .xlsm, tens que enviar zipado.
depois de procurares o ficheiro em causa, e te aparecer o caminho no campo, clicas em image. há-de aparecer-te qualquer coisa como img. isto contém o caminho para efectuar o upload do ficheiro. se clicares em previsualizar, não o verás, apenas quando clicas em enviar é que o ficheiro, tal como o post escrito, é registado no site.
jorgerod
Administradorboas, patropi,
é só tirar o seguinte segmento de código:
else
range(“c1”) = “”fica bem.
jorgerod
Administradorboas, patropi,
experimenta o seguinte código, pode ser que te resolva o problema:
private sub worksheet_selectionchange(byval target as range)
if range(“b1”).value = 1 then
range(“c1”) = range(“a1”)
range(“c1”).numberformat = “dd-mm-yyyy”
else
range(“c1”) = “”
end if
end subdiz qq coisa, ok?
jorgerod
Administradorboas, albino,
para somar todas as horas, talvez a seguinte fórmula:
=soma(a1:a3)

Soma_Horas_Albino_3.jpg
Soma_Horas_Albino_2.jpg
Soma_Horas_Albino_1.jpgAttachments:
You must be logged in to view attached files.jorgerod
Administradorobrigado.
olha, em que país estás? brasil? É que, em portugal, a função é É.texto(). talvez aí seja Étexto(). como eu digitei a função em excel português (pt-pt), o excel deve ter convertido para a linguagem que habitulmente utilizas. É como para inglês, as funções são automaticamente traduzidas.
fica bem e bom fim de semana.
jorgerod
Administradorpatropi,
reenvio-te a planilha. repara que apenas voltei a escrever a fórmula =se(É.texto(a1);”ok”;b1+b2) na célula a2. e deu certo…
talvez tivesses algum espaço no final da fórmula, de modo a que o erro aparecesse. experimenta agora e depois diz qq coisa, ok?
[file name=exemplo_exceler-20110430.zip size=8529]http://www.exceler.org/media/kunena/attachments/legacy/files/exemplo_exceler-20110430.zip[/file]
Exemplo_Exceler-20110430.zipjorgerod
Administradorpodes anexar uma planilha com esse erro?
jorgerod
Administradorexperimenta:
=se(É.texto(a1);”ok”;b1+b2)
fica bem e diz qq coisa.
jorgerod
Administradorolá pedro,
podes postar o código?
obrigado.
jorgerod
Administradorolá, pedro!
ainda bem que que te foi útil, é sempre um enorme prazer conseguir ajudar!! 🙂
aliás, é para isto que serve todo um trabalho de backoffice, que é feito em nome do exceler… afinal, tem tudo a ver com a finalidade do site: ajudar!!!!
como sabes, o ctrl+f2, dá o denominado print preview, mas apenas em termos da execução normal do excel. vê, por exemplo, as shortcuts em:
todavia, se quiseres utilizar o print preview através da tua macro, podes adicionar o seguinte código:
activewindow.selectedsheets.printpreview
agora, um pedido: quando tiveres isso prontinho, podes mandar-me? se não quiseres colocar aqui, podes mandar-me para o meu e-mail pessoal: jorge.rodrigues@exceler.org.
seria, para mim, um enorme prazer, ter o resultado final do teu trabalho.
fica bem e diz qq coisa, ok?
-
AutorArtigos
EXCELer Tudo sobre EXCEL em Português