buscar en un rango con una macro

Trufa

New Member
Joined
Oct 29, 2002
Messages
12
Tengo una MACRO que llama un formulario en el formulari hay 2 textbox uno donde yo escribo lo quiero buscar en un rango determinado de la planilla otro que me da el valor de la celda que esta al lado, ahora no logro que excel busque solo en el rango, primero busca y cuando encuentra el ultimo, desactiva el rango y continua su busqueda en toda la planilla. ¿Hay Solucion?

Este es el Codigo que tiene el formulario
Private Sub AGENTE_Change()

End Sub

Private Sub CommandButton2_Click()
Dim agen As String
agen = AGENTE.Text
Cells.Find(What:=agen, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= _
False).Activate
COD.Text = ActiveCell.Offset(0, -1).Value


End Sub

Private Sub UserForm_Activate()
Range("IU:IU").Select
End Sub
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Pues es el que código está haciendo lo que está escrito...

Con esto:

Cells.Find(...)

se le está diciendo a VBA que busque en toda la hoja ! no en el rango seleccionado...

A propósito, no hay necesidad de seleccionar / activar nada aquí:

Code:
COD.Text = Range("IU:IU").Find(What:=agen, After:=ActiveCell, LookIn:=xlFormulas, LookAt _ 
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:= False).Offset(0, -1).Value
 
Upvote 0
Re: buscar en un rango con una macro ese codigo no me respon

Private Sub CommandButton2_Click()
Dim agen As String
agen = AGENTE.Text
COD.Text = Range("IU:IU").Find(What:=agen, After:=ActiveCell, LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False).Offset(0, -1).Value



End Sub

Esto no funciona al menos en el excel 97.
No encuentra y ademas si encuentra algo y hay algo mas abajo con las mismas caracteristicas no lo busca.
 
Upvote 0
Porqué "esto no funciona" ?

Y el código que se mostró en la primera pregunta busca la primera coincidencia, no todas las existentes... así que no veo cuál es la diferencia con el que mostré...
 
Upvote 0

Forum statistics

Threads
1,215,737
Messages
6,126,562
Members
449,318
Latest member
Son Raphon

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top