Adding Text into cells

cart0250

Active Member
Joined
Jun 24, 2006
Messages
275
The below code enters text into cells based on the number held by the variable named xtraboard. If xtraboard is one, it enters WED into A65; if xtraboard is two, it enters WED into A65 and THU into A66 etc. through xtraboard=30. The below works fine, but I am wondering if there is a better, more efficient way to do this.

Sub board(xtraboard)
Range("A65:A94").ClearContents
Range("A65").Select
If xtraboard = 1 Then
ActiveCell.Resize(1) = Application.Transpose(Array("WED"))
Else
If xtraboard = 2 Then
ActiveCell.Resize(2) = Application.Transpose(Array("WED", "THU"))
Else
If xtraboard = 3 Then
ActiveCell.Resize(3) = Application.Transpose(Array("WED", "THU", "SUN"))
Else
If xtraboard = 4 Then
ActiveCell.Resize(4) = Application.Transpose(Array("WED", "THU", "FRI", "SUN"))
Else
If xtraboard = 5 Then
ActiveCell.Resize(5) = Application.Transpose(Array("TUE", "WED", "THU", "FRI", "SUN"))
Else
If xtraboard = 6 Then
ActiveCell.Resize(6) = Application.Transpose(Array("TUE", "WED", "THU", "FRI", "SAT", "SUN"))
Else
If xtraboard = 7 Then
ActiveCell.Resize(7) = Application.Transpose(Array("TUE", "WED", "WED", "THU", "FRI", "SAT", "SUN"))
Else
If xtraboard = 8 Then
ActiveCell.Resize(8) = Application.Transpose(Array("TUE", "WED", "WED", "THU", "THU", "FRI", "SAT", "SUN"))
Else
If xtraboard = 9 Then
ActiveCell.Resize(9) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "THU", "THU", "FRI", "SAT", "SUN"))
Else
If xtraboard = 10 Then
ActiveCell.Resize(10) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "THU", "THU", "FRI", "FRI", "SAT", "SUN"))
Else
If xtraboard = 11 Then
ActiveCell.Resize(11) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "THU", "THU", "FRI", "FRI", "SAT", "SAT", "SUN"))
Else
If xtraboard = 12 Then
ActiveCell.Resize(12) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "THU", "THU", "FRI", "FRI", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 13 Then
ActiveCell.Resize(13) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "FRI", "FRI", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 14 Then
ActiveCell.Resize(14) = Application.Transpose(Array("TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 15 Then
ActiveCell.Resize(15) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 16 Then
ActiveCell.Resize(16) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "FRI", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 17 Then
ActiveCell.Resize(17) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SUN", "SUN"))
Else
If xtraboard = 18 Then
ActiveCell.Resize(18) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 19 Then
ActiveCell.Resize(19) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 20 Then
ActiveCell.Resize(20) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 21 Then
ActiveCell.Resize(21) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 22 Then
ActiveCell.Resize(22) = Application.Transpose(Array("TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 23 Then
ActiveCell.Resize(23) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN"))
Else
If xtraboard = 24 Then
ActiveCell.Resize(24) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 25 Then
ActiveCell.Resize(25) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 26 Then
ActiveCell.Resize(26) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 27 Then
ActiveCell.Resize(27) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 28 Then
ActiveCell.Resize(28) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 29 Then
ActiveCell.Resize(29) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN"))
Else
If xtraboard = 30 Then
ActiveCell.Resize(30) = Application.Transpose(Array("TUE", "TUE", "TUE", "TUE", "TUE", "WED", "WED", "WED", "WED", "WED", "THU", "THU", "THU", "THU", "THU", "FRI", "FRI", "FRI", "FRI", "FRI", "SAT", "SAT", "SAT", "SAT", "SAT", "SUN", "SUN", "SUN", "SUN", "SUN"))

End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If: End If
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Cbrine

Well-known Member
Joined
Dec 2, 2003
Messages
3,196
You might want use a select case instead of multiple if's.
Code:
Sub board(xtraboard) 
Dim cell as range

Range("A65:A94").ClearContents 

set cell = range("A65")
Select Case xtraboard

Case 1
cell.Resize(1) = Application.Transpose(Array("WED")) 
Case 2
cell.Resize(2) = Application.Transpose(Array("WED", "THU")) 
Case 3
etc....
End select

HTH
Cal
 

Forum statistics

Threads
1,136,269
Messages
5,674,743
Members
419,525
Latest member
helensesc

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
Top