Recherche d'un textbox dans une colonne dans excel

Frankiai

New Member
Joined
Sep 28, 2006
Messages
6
Boujour a tous je suis nouveau ici

Merci a l'avance pour votre réponce

J'ai un problème avec une fonction dans vba excel

Je veut faire une recherche a partir d'un textbox qui est dans un userform
et la recherche ce fait dans une collone dans un worksheet

voici ce que j'ai penssé

if textbox.value = range (ai6:ai3000).select then
msgbox ("ce texte est deja dans la base de donné")

Merci Francois
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I can read French somewhat. But I cannot write it well (my grammar borders on criminal!) But you'll need something like so:
Code:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    If Not Range("Sheet1!A1:A5").Find(Me.TextBox1.Value) Is Nothing Then
        MsgBox "ce texte est deja dans la base de donné", vbInformation, "Already exists"
        Cancel = True
    End If
End Sub

Regards,
 
Upvote 0
Peut-etre comme ca:

Code:
Sub test()
    Set rng = Range("AI6:AI3000")
    a = Application.WorksheetFunction.CountIf(rng, textbox.value)
    If a > 0 Then
        MsgBox ("ce texte est deja dans la base de donné")
    End If
End Sub
 
Upvote 0
Ca ne marche pas / no dos not work

voici mon code avec la ligne qui ne fonctionne pas.


Code:
'---------------- Nouvelle Job & soumission -------------------

Private Sub CommandButton7_Click()

a = ComboBox3.Text

b = TextBox1.Text

c = TextBox2.Text

e = TextBox6.Text

Range("aj5") = Now()

dnes = Range("aj5")

client = b

desc = c

commatl = e

If a = "Francois Desrochers" Then a = "FD"

If a = "Jacques Garnier" Then a = "JG"

If a = "Nathalie Bouchard" Then a = "NB"

If a = "melanie cote" Then a = "MC"

If a = "Pierre Duchesne" Then a = "PD"

If a = "Marc Péloquin" Then a = "MP"

If a = "Mathieu Bastien" Then a = "MB"

If a = "Gilles Levesque" Then a = "GL"

If a = "Piero Zampino" Then a = "PZ"

If a = "Jean Lambert" Then a = "JL"

If a = "Alexandre Cartier" Then a = "AC"

If a = "Denis Blouin" Then a = "DB"

If a = "Genevieve Tanguay" Then a = "GT"

If a = "Pierrick Blondel" Then a = "PB"

If TextBox6.Text = "" Then

        MsgBox ("Le no. job ou soum. est requis")

    ElseIf ComboBox3.Text = "" Then

        MsgBox ("Sélectioner votre nom")

    ElseIf TextBox1.Text = "" Then

        MsgBox ("Écrire le nom du client")

    ElseIf TextBox2.Text = "" Then

        MsgBox ("Écrire une description")

    ElseIf e = "" Then

        TextBox6.Text = "Job requis"

    ElseIf TextBox6.Value = Range("AI6:AI3000") Then

        MsgBox ("Le no. de job existe déja dans la base de donnée")

Else

      Open "g:\data\" & e & ".txt" For Output As #1

        Write #1, dnes, client, desc, commatl, 0, 0, 0, 0, a

        Close #1

              Open "g:\data\nojob.txt" For Append As #3

                Write #3, commatl

                Close #3

TextBox1 = ""

TextBox2 = ""

TextBox6 = ""

ComboBox3 = ""

End If

Range("BK1").Select

End Sub
 
Upvote 0
Again, I apologize for not being able to respond in French. Normally I'd PM Erik, but he should be sleeping about now. So all of the French in this post is machine translated! :rolleyes: Encore, je fais des excuses pour ne pas pouvoir répondre en français. Normalement je P.M. Erik, mais il devrait dorme environ maintenant. Tellement tout les Français dans ce poteau est traduit par ordinateur !

  1. The first thing you need to do is to get into the habit of better coding, especially better variable and control naming. If your English is not very good, this might seem like a lot to read. But have a look at using the Hungarian conventions. This makes the code much easier to read.
    La première chose que vous devez faire est d'entrer dans l'habitude d'une meilleure meilleure de variable et de commande appellation de codage, particulièrement. Si votre anglais n'est pas très bon, ceci pourrait sembler comme beaucoup lire. Mais aller voir employer les conventions hongroises. Ceci facilite le code beaucoup pour lire.<hr />
  2. Using the Hungarian Convention rename the controls on your userform. You don't need to follow Gregory Reddick exactly, but try to stay close.
    En utilisant la convention hongroise retitrer les commandes sur votre userform. Vous n'avez pas besoin de suivre Gregory Reddick exactement, mais essayez de rester étroit. <hr />
  3. Move the name to letters conversion into a separate function.
    Déplacer le nom à la conversion de lettres dans une fonction séparée. <hr />
  4. Use constants for things like file paths. In case the path changes, it is much easier to locate what need to be updated.
    Employer les constantes pour des choses comme des chemins de dossier. Au cas où le chemin changerait, il est beaucoup plus facile de localiser quel besoin d'être mis à jour. <hr />
  5. Use FREEFILE to create file handles. You never know what other processes may have opened file handles.
    Employer FREEFILE pour créer des poignées de dossier. Vous ne savez jamais ce que d'autres processus ont pu avoir ouvert des poignées de dossier. <hr />
  6. Due to your use of variables like a, b, c, d, e,...textbox1, textbox2, textbox3,... I lost track of what variable is what. So sometime I put ______ or XXXXX.
    En raison de votre utilisation des variables aimera, b, c, d, e,… textbox1, textbox2, textbox3,… j'a perdu la voie de quelle variable est ce qui. Tellement autrefois j'ai mis le ______ ou XXXXX. <hr />
  7. I'm sure you already realize that you didn't quite get the CODE tags to work. You might experiment in our TEST FORUM to practice using them.
    Je suis sûr que vous vous rendez compte déjà que vous n'avez pas tout à fait obtenu les étiquettes de CODE pour fonctionner. Vous pourriez expérimenter dans notre FORUM d'ESSAI pour pratiquer les employer.
Code:
Private Sub btnOK_Click()

    Const c_strPath As String = "G:\Data\"
    
    Dim strName As String, strClient As String, strJob As String, _
        strDesc As String
    Dim booOKtoWriteFile As Boolean, intHandle As Integer
    
    booOKtoWriteFile = True
    strClient = tbxClient.Text
    strJob = tbxJob.Text
    strDesc = tbxDesc.Text
    
    Range("aj5") = Now()
    dnes = Range("aj5")

    If cbxName.Text <> "" Then
        strName = fnNameToInit(cbxName.Text)
    Else
        MsgBox "Sélectioner votre nom", vbExclamation
        booOKtoWriteFile = False
    End If

    If strJob = "" Then
        MsgBox "Le no. job ou soum. est requis", vbExclamation
        booOKtoWriteFile = False
    End If
    
    If strClient = "" Then
        MsgBox "Écrire le nom du client", vbExclamation
        booOKtoWriteFile = False
    End If
    
    If strClient = "" Then
        MsgBox "Écrire une description", vbExclamation
        booOKtoWriteFile = False
    End If
    
    If Not Range("Sheet1!AI6:AI30000").Find(Me.tbxJob.Text) Is Nothing Then
        MsgBox "ce texte est deja dans la base de donné", vbInformation, "Already exists"
        booOKtoWriteFile = False
    End If
End Sub

If booOKtoWriteFile Then

    intHandle = FreeFile
    Open c_strPath & "_________" & ".txt" For Output As #intHandle
    Write #intHandle, dtmNew, strClient, strDesc, strXXXX, 0, 0, 0, 0, strName

    Close #intHandle

    Open c_strPath & "nojob.txt" For Append As #intHandle

    Write #intHandle, strXXXX
    Close #intHandle

    tbxName = ""
    tbxJob = ""
    tbxClient = ""
    tbxDesc = ""

End If

Range("BK1").Select

End Sub

Private Function fnNameToInit(strInput As String) As String

    Dim strTemp As String, intPos As Integer
    
    strTemp = Left(strInput, 1)
    intPos = InStr(1, strInput, " ")
    If intPos <> 0 _
    And intPos < Len(strInput) Then
        strTemp = strTemp & Mid(strTemp, intPos + 1, 1)
    End If
    
    '// Any exceptions, i.e. names that would result
    '// in a duplicate value.  For example my name
    '// would yield the same value as Genevieve.
    '// So override the default results.
    
    If UCase(strInput) = "GREG TRUBY" Then
        strTemp = "GT1"
    ElseIf UCase(strInput) = "MARLON BRANDO" Then
        strTemp = "MB1"
    End If
    
    fnNameToInit = strTemp
    
End Function
 
Upvote 0
Thank you for all that

Sorry for my poor english :(

Thank's Greg for all the help

I will do bether next time i am new in this kind of message board
and thank you for writing the code for me. :biggrin:

Francois
 
Upvote 0
I've written a note to a friend and fellow MVP who speaks French and is adept at VBA, letting him know about this thread. So if you have any more questions, don't worry about writing them in French.

J'ai écrit une note à un ami et camarade MVP qui parle français et est versé à VBA, le faisant savoir ce fil. Ainsi si vous avez plus de questions, ne pas les inquiéter de l'écriture en français.
 
Upvote 0
Me voila :) Greg m'a envoyé un petit message.
Si tu as plus de questions, vas-y. Je ferai de mon mieux pour te répondre.
 
Upvote 0
Bonjour erik.van.geit

Boujour erik

La routine n'a pa fonctioné car je sait pas si j'ai tout fait correct
car je ne suis pas un programeur en vba. je fait cette petite routine pour me facilité la tache dans mon travail, je vais t'expliqué ce que je veut faire et si tu veut m'aider je serai tres tres heureux

a partire d'une boite de dialogue (en appuillant sur un bouton) allez chercher sur une page d'excel une colonne complet, aller voir si un numéro que j'aurais écrit dans un textbox est deja dans cette colonne si oui ecrire un message d'erreur qui dit (le no. job existe deja)

Merci erik a l'avance
 
Upvote 0

Forum statistics

Threads
1,213,489
Messages
6,113,949
Members
448,534
Latest member
benefuexx

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