Good Evening all the experts out there. Need help in VBA Excel macro in for each - for next looping

Rahul Soni

New Member
Joined
Dec 17, 2022
Messages
5
Office Version
  1. 2010
Platform
  1. Windows
I am working on a free school project and trying to build an automated system for assigning substitue teachers. I have done alsmot everything but need help in For Each - for next loop to plug in teachers if someone is absent on a given day. The code I wrote so far is looping but not assigning the values one by one. I know something smaller is missing hence need your kind help.

What I need is that : for each red highlighted cell on Time Table sheet - below the highlighted cell a teacher name should be populated from Info sheet column f and it should continue till all the red highlighted cells have been populated with the unique names from Info sheet column F.

Sub setasignee()

Dim rSH As Worksheet

Dim sSH As Worksheet



Set rSH = ThisWorkbook.Sheets("Time Table")
Set sSH = ThisWorkbook.Sheets("Info")

Set Rng = rSH.Range("D5:AU64")


'a = sSH.Range("F" & Rows.Count).End(xlUp).Row



'Dim fName As String








For a = 2 To sSH.Range("F" & Rows.Count).End(xlUp).Row

fName = sSH.Range("F" & a).Value

For Each c In Rng

If c.Interior.ColorIndex = 3 And c.Value <> "" Then



c.Offset(1, 0).Value = fName

'If c.Offset(1, 0).Value <> "" Then Exit For






End If


Next c


Next a



'Next a





End Sub
 
You're welcome. Glad I could help.
If you're list of names it long then the next step would be to convert the Names range to an array to speed it up.
 
Upvote 0

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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