heldercorreia Posted September 8, 2009 at 05:12 PM Report Share #286107 Posted September 8, 2009 at 05:12 PM Viva malta, venho pedir a vossa opinião/sugestões quanto ao seguinte: Necessito de preencher células no excel, de tal forma que não seja em posições fixas. Assim sendo, engendrei a seguinte função, a qual recebe em argumento a posição inicial da sequencia de células a serem preenchidas. Private Function dados_motor(p, n) 'Escreve na folha de cálculo os dados relativos ao Sheet2.Range(p).Select 'motor a contar da posição recebida em argumento Sheet2.Range(p).Value = "Motor " & n ActiveCell.Offset(1, 0).Select Call supersub("UrM (V)", 0, 2, 2, 0) ActiveCell.Offset(1, 0).Select Call supersub("SrM (VA)", 0, 2, 2, 0) ActiveCell.Offset(1, 0).Select Call supersub(ChrW(981) & "rM (º)", 0, 2, 2, 2) ActiveCell.Offset(1, 0).Select Call supersub("ILR/IrM", 0, 2, 2, 0) ActiveCell.Offset(1, 0).Select Call supersub("RM/XM", 0, 2, 0, 0) Sheet2.Range(p).Select ActiveCell.Offset(1, 1).Select ActiveCell.Value = "400" ActiveCell.Offset(1, 0).Select ActiveCell.Value = "20000" ActiveCell.Offset(1, 0).Select ActiveCell.Value = "0.15" ActiveCell.Offset(1, 0).Select ActiveCell.Value = "8" ActiveCell.Offset(1, 0).Select ActiveCell.Value = "0.3" End Function Pronto.. como podem ver não me parece lá grande solução, vá funciona mas acho que é um bocado mau do ponto de vista de programação. Alguma alternativa/sugestões adicionais? Ah, falta indicar o que é a função Supersub que tantas vezes chamo: Private Sub supersub(b, c, d, e, f) 'Coloca certos caracteres em expoente ou índice ActiveCell.Value = b With ActiveCell.Characters(Start:=1, Length:=1).Font .Superscript = issuper(c) .Subscript = issub(c) End With With ActiveCell.Characters(Start:=2, Length:=1).Font .Superscript = issuper(d) .Subscript = issub(d) End With With ActiveCell.Characters(Start:=3, Length:=1).Font .Superscript = issuper(e) .Subscript = issub(e) End With With ActiveCell.Characters(Start:=4, Length:=1).Font .Superscript = issuper(f) .Subscript = issub(f) End With End Sub E ainda: Public Function issub(f) As Boolean 'Retorna 1 se caracter for índice If f = 2 Then issub = True Else issub = False End If End Function Private Function issuper(f) As Boolean 'Retorna 1 se caracter for expoente If f = 1 Then issuper = True Else issuper = False End If End Function Isto foi também uma maneira que arranjei de poder controlar caracter a caracter se é um expoente ou um índice, superior à linha, ou inferior. Peço que perdoem a extenção do texto, aceito também sugestões quanto a como apresentar melhor o meu problema para a próxima ? Link to comment Share on other sites More sharing options...
heldercorreia Posted September 13, 2009 at 07:05 PM Author Report Share #286814 Posted September 13, 2009 at 07:05 PM Bump.. Então malta, nenhuma sugestão para não ter que repetir ActiveCell.Offset(1, 0).Select Sempre que se pretende descer uma célula? Tou farto de e não chego a conclusão nenhuma 😉 Link to comment Share on other sites More sharing options...
jpaulino Posted September 13, 2009 at 07:26 PM Report Share #286817 Posted September 13, 2009 at 07:26 PM Olá, Mas não precisas de seleccionar para escrever um valor! Podes fazer algo como: Cells(linha, coluna).Value = "valor" Se sabes a primeira linha, podes fazer: Cells(linha+1, coluna).Value = "valor" Explica melhor o que queres e podem aparecer mais ideias ou então se puderes mostrar o ficheiro ... Link to comment Share on other sites More sharing options...
heldercorreia Posted September 14, 2009 at 04:54 PM Author Report Share #286959 Posted September 14, 2009 at 04:54 PM Muito boa ideia, e resolvia o meu problema se Cells(LIN(p), COL(p)).Value = valor funcionasse.. ou seja, recebo p em argumento e conseguia tirar de p as coordenadas. Já experimentei: Row() e Column() mas em ambiente excel funciona, em vba não.. Obtenho o erro: Compile error: sub or function not defined Link to comment Share on other sites More sharing options...
heldercorreia Posted September 14, 2009 at 11:47 PM Author Report Share #287058 Posted September 14, 2009 at 11:47 PM Resolvido com Cells(Range(p).Row, Range(p).Column).Value = valor De facto não podia ser como estava a pensar visto que a variável p é passada em argumento como STRING! ora uma string não tem como propriedades linha e coluna.. Sabe bem quando a resposta aparece ^^ obrigado p'la dica. Agora... outra coisita, alguma sugestão em como formatar o texto de uma célula caracter a caracter ? Necessito de escrever fórmulas matemáticas tipo: Un2 Link to comment Share on other sites More sharing options...
jpaulino Posted September 15, 2009 at 06:58 AM Report Share #287068 Posted September 15, 2009 at 06:58 AM Agora... outra coisita, alguma sugestão em como formatar o texto de uma célula caracter a caracter ? Necessito de escrever fórmulas matemáticas tipo: Un2 E qual e o critério ? Sugiro que cries um novo tópico com mais detalhes 😉 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now