Hi guys.
Is there anyway to use, say a for loop, to shorten this code?
Code
Location(1) = UserForm2.TextPlace1.Text
Location(2) = UserForm2.TextPlace2.Text
Location(3) = UserForm2.TextPlace3.Text
Location(4) = UserForm2.TextPlace4.Text
Location(5) = UserForm2.TextPlace5.Text
Location(6) = UserForm2.TextPlace6.Text
Location(7) = UserForm2.TextPlace7.Text
Location(8) = UserForm2.TextPlace8.Text
Location(9) = UserForm2.TextPlace9.Text
Location(10) = UserForm2.TextPlace10.Text
Location(11) = UserForm2.TextPlace11.Text
Location(12) = UserForm2.TextPlace12.Text
Location(13) = UserForm2.TextPlace13.Text
Location(14) = UserForm2.TextPlace14.Text
Location(15) = UserForm2.TextPlace15.Text
Location(16) = UserForm2.TextPlace16.Text
Location(17) = UserForm2.TextPlace17.Text
Location(18) = UserForm2.TextPlace18.Text
Location(19) = UserForm2.TextPlace19.Text
Location(20) = UserForm2.TextPlace20.Text
Location(21) = UserForm2.TextPlace21.Text
Location(22) = UserForm2.TextPlace22.Text
Location(23) = UserForm2.TextPlace23.Text
Location(24) = UserForm2.TextPlace24.Text
Location(25) = UserForm2.TextPlace25.Text
Location(26) = UserForm2.TextPlace26.Text
Location(27) = UserForm2.TextPlace27.Text
Location(28) = UserForm2.TextPlace28.Text
Location(29) = UserForm2.TextPlace29.Text
Location(30) = UserForm2.TextPlace30.Text
Location(31) = UserForm2.TextPlace31.Text
Location(32) = UserForm2.TextPlace32.Text
Location(33) = UserForm2.TextPlace33.Text
Location(34) = UserForm2.TextPlace34.Text
Location(35) = UserForm2.TextPlace35.Text
Location(36) = UserForm2.TextPlace36.Text
Location(37) = UserForm2.TextPlace37.Text
Location(38) = UserForm2.TextPlace38.Text
Location(39) = UserForm2.TextPlace39.Text
Location(40) = UserForm2.TextPlace40.Text
Location(41) = UserForm2.TextPlace41.Text
Location(42) = UserForm2.TextPlace42.Text
Location(43) = UserForm2.TextPlace43.Text
Location(44) = UserForm2.TextPlace44.Text
Location(45) = UserForm2.TextPlace45.Text
Location(46) = UserForm2.TextPlace46.Text
Location(47) = UserForm2.TextPlace47.Text
Location(48) = UserForm2.TextPlace48.Text
FileName = UserForm1.TextBox2.Text
'Error handling. "BadEntry" is located at the end of the procedure.
On Error GoTo BadEntry
'Checks cells to see which location name to run the keywords for.
Windows(FileName & ".xls").Activate
Sheets("sheet1").Select
If Range("D191") = "" Then
UserPlace = Location(1)
ElseIf Range("D191") <> "" And Range("D381") = "" Then
UserPlace = Location(2)
ElseIf Range("D381") <> "" And Range("D571") = "" Then
UserPlace = Location(3)
ElseIf Range("D571") <> "" And Range("D761") = "" Then
UserPlace = Location(4)
ElseIf Range("D761") <> "" And Range("D951") = "" Then
UserPlace = Location(5)
ElseIf Range("D951") <> "" And Range("D1141") = "" Then
UserPlace = Location(6)
ElseIf Range("D1141") <> "" And Range("D1331") = "" Then
UserPlace = Location(7)
ElseIf Range("D1331") <> "" And Range("D1521") = "" Then
UserPlace = Location(8)
ElseIf Range("D1521") <> "" And Range("D1711") = "" Then
UserPlace = Location(9)
ElseIf Range("D1711") <> "" And Range("D1901") = "" Then
UserPlace = Location(10)
ElseIf Range("D1901") <> "" And Range("D2091") = "" Then
UserPlace = Location(11)
ElseIf Range("D2091") <> "" And Range("D2281") = "" Then
UserPlace = Location(12)
ElseIf Range("D2281") <> "" And Range("D2471") = "" Then
UserPlace = Location(13)
Display More
I can't think of anything of the top of my head!