Hello,
This is my first VBA- project and I need a help
I have a userform with serveral textboxes
In the first of those textboxes, I put the varialel "NR_Agent" ( e.g. B1385, OR A6985) before clicking on my command button (Rechercher_Agent).
By clicking, the macro will automatically fill out the other text-and checkboxes. ( e.g. Name, Telefonsnumber etc...)
My code is working perfectly
Depending on the "NR_Agent", the macro is also uploading a picture ( Selfi that has been saved as "B1385 OR A6985") -> works also!
Here my problem:
I have +- 250 agents with an "agent-number" in my Excel, but I do not have picture from everyone. When I put the variable "NR_Agent" of an agent where I do not have a picture I get an error message " no input found"
Which is evident and normal, but I don't know how to write the code "if there is a picture -> upload it, if there is no picture -> continue"
Here is my code:
Private Sub Recherche_Agent_Form_Click()
Dim NR_Agent As String
NR_Agent =Trim(Userform1.Texbox1.Text)
lastrow = Worksheet("Sheet1").Cells(Rows.Count,1).End(xlUp).Row
For i = 3 To lastrow
If worksheets("Sheet1").Cells(i,1).Value = NR_Agent Then
Userform1.Textbox2.Text = Worksheet("Sheet1").Cells(i,2).Value
Userform1.Textbox3.Text = Worksheet("Sheet1").Cells(i,3).Value
Image1.Picture =LoadPicture("U:\Picture\" & Texbox1.Text & ".jpg")
Does anyone know how to do?
Thank you
This is my first VBA- project and I need a help
I have a userform with serveral textboxes
In the first of those textboxes, I put the varialel "NR_Agent" ( e.g. B1385, OR A6985) before clicking on my command button (Rechercher_Agent).
By clicking, the macro will automatically fill out the other text-and checkboxes. ( e.g. Name, Telefonsnumber etc...)
My code is working perfectly
Depending on the "NR_Agent", the macro is also uploading a picture ( Selfi that has been saved as "B1385 OR A6985") -> works also!
Here my problem:
I have +- 250 agents with an "agent-number" in my Excel, but I do not have picture from everyone. When I put the variable "NR_Agent" of an agent where I do not have a picture I get an error message " no input found"
Which is evident and normal, but I don't know how to write the code "if there is a picture -> upload it, if there is no picture -> continue"
Here is my code:
Private Sub Recherche_Agent_Form_Click()
Dim NR_Agent As String
NR_Agent =Trim(Userform1.Texbox1.Text)
lastrow = Worksheet("Sheet1").Cells(Rows.Count,1).End(xlUp).Row
For i = 3 To lastrow
If worksheets("Sheet1").Cells(i,1).Value = NR_Agent Then
Userform1.Textbox2.Text = Worksheet("Sheet1").Cells(i,2).Value
Userform1.Textbox3.Text = Worksheet("Sheet1").Cells(i,3).Value
Image1.Picture =LoadPicture("U:\Picture\" & Texbox1.Text & ".jpg")
Does anyone know how to do?
Thank you