x_soldier Posted December 20, 2012 at 06:23 PM Report #487986 Posted December 20, 2012 at 06:23 PM Boas pessoal. Tenho andado a googlar e ainda não me safei, como é possivel fazer um like em VBA?? Já tentei de algumas formas, parecendo-me esta a mais correcta mas não me oriento: If (Cells(j, "Q").Value) Like "86000/5*" Then Alguém dá uma ajudinha?? Obrigado
acao Posted December 20, 2012 at 06:33 PM Report #487988 Posted December 20, 2012 at 06:33 PM (edited) Boas pessoal. Tenho andado a googlar e ainda não me safei, como é possivel fazer um like em VBA?? Já tentei de algumas formas, parecendo-me esta a mais correcta mas não me oriento: If (Cells(j, "Q").Value) Like "86000/5*" Then Alguém dá uma ajudinha?? Obrigado boas tenta assim If Like '%" & (Cells(j, "Q").Value) & "%' Then ou If Like '*" & (Cells(j, "Q").Value) & "*' Then nao testei mas deve funcionar cumps acao Edited December 20, 2012 at 06:37 PM by acao
x_soldier Posted December 21, 2012 at 09:29 AM Author Report #488017 Posted December 21, 2012 at 09:29 AM boas tenta assim If Like '%" & (Cells(j, "Q").Value) & "%' Then ou If Like '*" & (Cells(j, "Q").Value) & "*' Then nao testei mas deve funcionar cumps acao Boas, Não está a funcionar, dá logo erro no código. O que eu queria neste código era que me elimina-se todas as linhas começadas por 86000/5. Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 2 Step -1 If (Cells(j, "E").Value) = "860000/5" Then Cells(j, "A").EntireRow.Delete End If Next j End Sub
acao Posted December 21, 2012 at 03:15 PM Report #488044 Posted December 21, 2012 at 03:15 PM Boas, Não está a funcionar, dá logo erro no código. O que eu queria neste código era que me elimina-se todas as linhas começadas por 86000/5. Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 2 Step -1 If (Cells(j, "E").Value) = "860000/5" Then Cells(j, "A").EntireRow.Delete End If Next j End Sub boas não é a função like que deves utilizar mas sim a função Left$ tens um exemplo: http://www.macoratti.net/strings.htm cumps acao
FreiNando Posted December 21, 2012 at 04:34 PM Report #488052 Posted December 21, 2012 at 04:34 PM (edited) Like é um operador lógico, logo não pode ser usado como função. A forma como tinhas é a correcta: Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 2 Step -1 If Cells(j, "E").Value Like "860000/5*" Then Cells(j, "A").EntireRow.Delete End If Next j End Sub A falha deve ser por outro motivo. Edited December 21, 2012 at 04:41 PM by FreiNando O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles
x_soldier Posted December 21, 2012 at 05:07 PM Author Report #488056 Posted December 21, 2012 at 05:07 PM Like é um operador lógico, logo não pode ser usado como função. A forma como tinhas é a correcta: Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 2 Step -1 If Cells(j, "E").Value Like "860000/5*" Then Cells(j, "A").EntireRow.Delete End If Next j End Sub A falha deve ser por outro motivo. Segundo o que dizes é que não posso usar o like numa função deste calibre?? Simplesmente ignora-me 😕 Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 1 Step -1 If (Cells(j, "E").Value) = Left("86000/5", 6) Then Cells(j, "A").EntireRow.Delete End If Next j End Sub
jpaulino Posted December 21, 2012 at 08:15 PM Report #488066 Posted December 21, 2012 at 08:15 PM Segundo o que dizes é que não posso usar o like numa função deste calibre?? Sim podes e o FreiNando até te mostrou um exemplo. O primeiro exemplo que mostraste está correcto por isso o erro deve ser em outro local.
FreiNando Posted December 21, 2012 at 09:25 PM Report #488073 Posted December 21, 2012 at 09:25 PM Agora caí de quatro... Segundo o que dizes é que não posso usar o like numa função deste calibre?? Simplesmente ignora-me 😕 Sub Button2_Click() Sheets("Bookkeeping").Select Last = Cells(Rows.Count, "E").End(xlUp).Row For j = Last To 1 Step -1 If (Cells(j, "E").Value) = Left("86000/5", 6) Then Cells(j, "A").EntireRow.Delete End If Next j End Sub Left("86000/5",6) = "86000/" ou não? Adiante... Todo o programador deve conhecer os operadores, sejam eles aritméticos, comparação, concatenação, ou lógicos. A ajuda do VBA possui muita informação sobre este assunto. Vai à ajuda (F1) e no indice começa aqui: Excel 2010 Developer Reference > Visual Basic for Applications Language Reference > Visual Basic Language Reference > Operators O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles
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