Create an Excel VBA form using a loop to source the inputs

MrPink1986

Active Member
Joined
May 1, 2012
Messages
252
Hi,

I have a list of soccer games on sheet "Web Import" with team A in column C and team B in column E. I want to create a user from for a user to input scores for these games. So when the user form pops up (once the spreadsheet is opened) it should present the user with the teams from the first game, these values will be in C2 and E2. The user should be presented with an input box under team to enter a number. Once they have done this there should be a confirm button and the form should then look to display the teams from the 2nd game i.e. C3 and E3 all the way down until there are no values in C and E (should be 10 iterations)
Once there are no more games a text box should appear asking the user to enter their name.

All the information which has been entered by the user needs to be exported to the results tab beginning with cell A2

I dont have any experience using forms in Excel so your help is very much appreciated.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
I have created my form to work for the first iteration of my matches. When I open my spreadsheet the home and away team populates from my tab Web Import tab. The user then needs to enter scores in to HomeScore & AwayScore. Once that it is done the user needs to hit a command button, Confirm, which takes the values from the 4 text boxes and paste the data onto my welcome sheet.

After this I want the text boxes to be cleared.
Then the HomeTeam text box should update to Sheets("Web Import").Range("C3") and the AwayTeam text box should update to Sheets("Web Import").Range("E3") the user should then enter values into HomeScore and AwayScore text boxes.
User should hit the command button "Confirm" and this should copy and paste this data in to A8, C8, B8 and D8.

After this it should loop through the values on the web import sheet until there are no values in Column C (usually 10 iterations)

Code:
Private Sub AwayTeam_Change()

AwayTeam.Value = Sheets("Web Import").Range("E2")


End Sub




Private Sub HomeTeam_Change()


HomeTeam.Value = Sheets("Web Import").Range("C2")




End Sub


Private Sub Confirm_Click()


Dim clipboard As MSForms.DataObject
Set clipboard = New MSForms.DataObject


clipboard.SetText Me.HomeTeam.text
clipboard.PutInClipboard
Range("A7").PasteSpecial


clipboard.SetText Me.AwayTeam.text
clipboard.PutInClipboard
Range("C7").PasteSpecial


clipboard.SetText Me.HomeScore.text
clipboard.PutInClipboard
Range("B7").PasteSpecial


clipboard.SetText Me.AwayScore.text
clipboard.PutInClipboard
Range("D7").PasteSpecial


End Sub


Private Sub AwayScore_Change()


End Sub


Private Sub HomeScore_Change()


End Sub


Private Sub UserForm_Initialize()


Call HomeTeam_Change
Call AwayTeam_Change


End Sub
 
Upvote 0

Forum statistics

Threads
1,223,901
Messages
6,175,277
Members
452,629
Latest member
SahilPolekar

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