Counter For Picture Update

Jaye7

Well-known Member
Joined
Jul 7, 2010
Messages
1,069
I am running a wintimer which I want a picture to update based on the value in textbox1.

Currently I am using the following but surely there is an eaiser script.

Code:
If UserForm1.TextBox1.Value = "1" Then
   UserForm1.Image1.Picture = UserForm1.Image2.Picture
   UserForm1.TextBox1.Value = "2"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "2" Then
   UserForm1.Image1.Picture = UserForm1.Image3.Picture
   UserForm1.TextBox1.Value = "3"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "3" Then
   UserForm1.Image1.Picture = UserForm1.Image4.Picture
   UserForm1.TextBox1.Value = "4"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "4" Then
   UserForm1.Image1.Picture = UserForm1.Image5.Picture
   UserForm1.TextBox1.Value = "5"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "5" Then
   UserForm1.Image1.Picture = UserForm1.Image6.Picture
   UserForm1.TextBox1.Value = "6"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "6" Then
   UserForm1.Image1.Picture = UserForm1.Image7.Picture
   UserForm1.TextBox1.Value = "7"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "7" Then
   UserForm1.Image1.Picture = UserForm1.Image8.Picture
   UserForm1.TextBox1.Value = "8"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "8" Then
   UserForm1.Image1.Picture = UserForm1.Image9.Picture
   UserForm1.TextBox1.Value = "9"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "9" Then
   UserForm1.Image1.Picture = UserForm1.Image10.Picture
   UserForm1.TextBox1.Value = "10"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "10" Then
   UserForm1.Image1.Picture = UserForm1.Image11.Picture
   UserForm1.TextBox1.Value = "11"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "11" Then
   UserForm1.Image1.Picture = UserForm1.Image12.Picture
   UserForm1.TextBox1.Value = "12"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "12" Then
   UserForm1.Image1.Picture = UserForm1.Image13.Picture
   UserForm1.TextBox1.Value = "13"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "13" Then
   UserForm1.Image1.Picture = UserForm1.Image14.Picture
   UserForm1.TextBox1.Value = "14"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "14" Then
   UserForm1.Image1.Picture = UserForm1.Image15.Picture
   UserForm1.TextBox1.Value = "15"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "15" Then
   UserForm1.Image1.Picture = UserForm1.Image16.Picture
   UserForm1.TextBox1.Value = "16"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "16" Then
   UserForm1.Image1.Picture = UserForm1.Image17.Picture
   UserForm1.TextBox1.Value = "17"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "17" Then
   UserForm1.Image1.Picture = UserForm1.Image18.Picture
   UserForm1.TextBox1.Value = "18"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "18" Then
   UserForm1.Image1.Picture = UserForm1.Image19.Picture
   UserForm1.TextBox1.Value = "19"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "19" Then
   UserForm1.Image1.Picture = UserForm1.Image20.Picture
   UserForm1.TextBox1.Value = "20"
   Exit Sub
   End If
 
 
    If UserForm1.TextBox1.Value = "20" Then
   UserForm1.Image1.Picture = UserForm1.Image21.Picture
   UserForm1.TextBox1.Value = "21"
   Exit Sub
   End If
 
   If UserForm1.TextBox1.Value = "21" Then
   UserForm1.Image1.Picture = UserForm1.Image22.Picture
   UserForm1.TextBox1.Value = "22"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "22" Then
   UserForm1.Image1.Picture = UserForm1.Image23.Picture
   UserForm1.TextBox1.Value = "23"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "23" Then
   UserForm1.Image1.Picture = UserForm1.Image24.Picture
   UserForm1.TextBox1.Value = "24"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "24" Then
   UserForm1.Image1.Picture = UserForm1.Image25.Picture
   UserForm1.TextBox1.Value = "25"
   Exit Sub
   End If
 
    If UserForm1.TextBox1.Value = "25" Then
   UserForm1.Image1.Picture = UserForm1.Image2.Picture
   UserForm1.TextBox1.Value = "1"
   Exit Sub
   End If

I would like to get rid of the if statements and have a simple formula like
the following (which of course doesn't work.

Code:
userform1.image1.picture = userform1.image & (userform1.textbox1.value).picture


.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Look into Case Statements.

Biz
 
Upvote 0
Thanks Biz but I don't think that a case statement will cut down the script to two or three lines total as a case statement you need to still put several lines of code for each statement.

It will cut it down but not to a very simple script.
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,610
Members
452,931
Latest member
The Monk

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