Macro/VBA for dividing a tabble

nicolas877

New Member
Joined
Jan 15, 2022
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hi forum , i have been looking for some vba code for doing this but i found no one yet. Basically it will be to do something like this ...lets say you have this table with the name colum in blank


CASENAME
2345​
4535​
5654​
2422​

To transform it to this , to assign half of the cases to mike , and half to susan (half of the table to one , and half to the other) , any sugestion ? thanks


CASENAME
2345​
Mike
4535​
Mike
5654​
Susan
2422​
Susan
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
How about simple.
Why not put "Mike" for the first case, then "Susan" for the second case, then do the Fast-Fill Down (Angry Rabbit)?
 
Upvote 0
How about simple.
Why not put "Mike" for the first case, then "Susan" for the second case, then do the Fast-Fill Down (Angry Rabbit)?
the real table has hundreds of rows but i need to dived at the middle and assign half of the casses to susan and half to mike
 
Upvote 0
Okay, a formula would be.
=IF(COUNT(A2:$A$403)/(COUNT(A:A))<=0.5,"Susan","Mike")
Then a Copy, Paste Values.

Could your list of Names grow?
Is your dataset a range or Table?
I know a lot of others on the forum can VBA this a lot faster than myself.
 
Upvote 0
In VBA, Note this assumes the NAME is not filled in and would overwrite any values.
Adjust the destination columns referenced.
VBA Code:
Sub CaseDivision()
Dim LastRow As Long
Dim MidRow As Long

Dim SS As Worksheet
Set SS = ActiveSheet
'Application.ScreenUpdating = False

LastRow = SS.UsedRange.Rows.Count

SS.Activate

LastRow = SS.UsedRange.Rows.Count
MidRow = Round(((LastRow - 1)) / 2, 0)


SS.Range("B2:B" & MidRow + 1).Value = "Mike"
SS.Range("B" & MidRow + 2 & ":B" & LastRow).Value = "Susan"
SS.Range("A1").Select

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,819
Messages
6,121,749
Members
449,050
Latest member
excelknuckles

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