Jump to content

Recommended Posts

Posted

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

Posted (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 by acao
Posted

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
Posted

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

Posted (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 by FreiNando

O caminho mais curto para conseguir fazer muitas coisas é fazer uma de cada vez. Samuel Smiles

Posted

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
Posted

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.

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.