VBA looping names from the list

Melkor

New Member
Joined
Oct 27, 2016
Messages
7
Hi guys,

Can you please help me with this issue?
I have a list with fruits (I2:I13), and I want to create VBA form with one lable and one button, where on the lable it will be written the name of the fruit (first on the list), and by clicking on the button it should change the name of the fruit which is next on the list, when it reach the end of the list it shoud start with first name on the list.

Just to mention, the list with fruits will be dinamic according to availability.
 

Attachments

  • Voce.jpg
    Voce.jpg
    96.4 KB · Views: 11
  • Form.jpg
    Form.jpg
    88.7 KB · Views: 11

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Welcome to the forum

Try below code for the command button
VBA Code:
Private Sub CommandButton1_Click()

Dim Rg As Range

Set Rg = Columns("i").Find(Label1.Caption, lookat:=xlWhole)
If Rg Is Nothing Then Label1.Caption = [i2] Else Label1.Caption = IIf(Rg.Offset(1) = "", [i2], Rg.Offset(1))

End Sub
 
Upvote 0
Hi mse330, than you for the warm welcome 🙏

Tried the code above, but on click it's showing just first article(name).
 

Attachments

  • Forma 1.jpg
    Forma 1.jpg
    47.7 KB · Views: 9
Upvote 0
It didn't work, because the data in I column was formula, so when I pasted just values, it was fixed.

Thank you, one more time
 
Upvote 0
If you need to retain your formulas & the code to work, you may add LookIn:=xlValues as shown in the below code

VBA Code:
Private Sub CommandButton1_Click()

Dim Rg As Range

Set Rg = Columns("i").Find(Label1.Caption, lookat:=xlWhole, LookIn:=xlValues)
If Rg Is Nothing Then Label1.Caption = [i2] Else Label1.Caption = IIf(Rg.Offset(1) = "", [i2], Rg.Offset(1))

End Sub
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,190
Members
452,616
Latest member
intern444

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