Help with loop function

jyokom

Board Regular
Joined
May 24, 2004
Messages
148
How can I simplify the following by utilizing the loop function?

Sub Crew1_Change()
Sheets("Setup").Calculate
TB_Pos1_1.Value = Sheets("Setup").Range("AJ9").Text
TB_Unit1_1.Value = Sheets("Setup").Range("AQ9").Text
TB_SSN1_1.Value = Sheets("Setup").Range("AT9").Text

TB_Pos1_2.Value = Sheets("Setup").Range("AJ10").Text
TB_Unit1_2.Value = Sheets("Setup").Range("AQ10").Text
TB_SSN1_2.Value = Sheets("Setup").Range("AT10").Text

TB_Pos1_3.Value = Sheets("Setup").Range("AJ11").Text
TB_Unit1_3.Value = Sheets("Setup").Range("AQ11").Text
TB_SSN1_3.Value = Sheets("Setup").Range("AT11").Text

TB_Pos1_4.Value = Sheets("Setup").Range("AJ12").Text
TB_Unit1_4.Value = Sheets("Setup").Range("AQ12").Text
TB_SSN1_4.Value = Sheets("Setup").Range("AT12").Text

TB_Pos1_5.Value = Sheets("Setup").Range("AJ13").Text
TB_Unit1_5.Value = Sheets("Setup").Range("AQ13").Text
TB_SSN1_5.Value = Sheets("Setup").Range("AT13").Text

End Sub
 
Just taking a stab in the dark but try...


Code:
Sub Crew1_Change_Loop()
     Dim i As Integer
     Sheets("Setup").Calculate

     For i = 1 To 5
         ActiveSheet.Range("TB_Pos1_" & i).Value = Sheets("Setup").Range("AJ8").Offset(i, 0).Text
         ActiveSheet.Range("TB_Unit1_" & i).Value = Sheets("Setup").Range("AQ8").Offset(i, 0).Text
         ActiveSheet.Range("TB_SSN1_" & i).Value = Sheets("Setup").Range("AT8").Offset(i, 0).Text
     Next i
 End Sub


Or if it's not doing its magic on the activesheet then change that sheet reference to whatever you want.

Again, just a stab in the dark

HTH

Hank
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

Forum statistics

Threads
1,224,586
Messages
6,179,723
Members
452,939
Latest member
WCrawford

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