Excel - read the name from different sheets and return back to another sheet in sequence

kmaungt

New Member
Joined
Jun 20, 2022
Messages
1
Office Version
  1. 2021
Platform
  1. Windows
Hi Excel experts ,kindly help to advise on this . For example , I have five names from other source and I wanted to return those name in sequence like in destination tab .


Below is my code in VBA , my problem can be solved by doing even and odd rows return if there's only two names . ( Please refer to 1st picture ) . But let's say I have five names or even more , but I wanted to return those name in sequence , how should I do it . ( 2nd picture ) Thanks in advance .

Sub AssignAgent()

Dim r As range
Dim i As Integer

For Each r In range("AE7:AE1000") 'Change this range

i = r.Row
If i Mod 2 = 1 Then 'this checks to see if i is odd
r.Cells.Value = "Mages"

Else
r.Cells.Value = "Yani"
End If

Next r

End Sub

1655779849998.png




1655779665486.png
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Is this what you mean?
Change references as required.
Code:
Sub Maybe()
Dim sh1 As Worksheet, sh2 As Worksheet
Dim tms As Long
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")
tms = sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row - 1
    sh1.Range("A2:A" & sh1.Cells(sh1.Rows.Count, 1).End(xlUp).Row).Copy sh2.Cells(1, 1).Resize(tms * tms)
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,608
Members
449,174
Latest member
ExcelfromGermany

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