Populating an Excel companion sheet with names continuing in a second - Microsoft Community
- Get link
- X
- Other Apps
this vba code should you. you'll have replace sheet names actuals. splits , copies names in column column , c of other 2 sheets after clearing names there.
sub pop_names()
dim lastrow long
dim halfrow long
dim moveamount long
dim x long
'clear names sheet2
worksheets("sheet2")
lastrow = .cells(.rows.count, "a").end(xlup).row
if lastrow > 1 then
.range("a2:a" & lastrow).clearcontents
.range("c2:c" & lastrow).clearcontents
end if
end with
'clear names sheet3
worksheets("sheet3")
lastrow = .cells(.rows.count, "a").end(xlup).row
if lastrow > 1 then
.range("a2:a" & lastrow).clearcontents
.range("c2:c" & lastrow).clearcontents
end if
end with
'get last row of names
worksheets("sheet1")
lastrow = .cells(.rows.count, "a").end(xlup).row
end with
'calc half of row length copying
halfrow = int(lastrow / 2) + 1
'copy half of names columns a
worksheets("sheet1").range("a2:a" & halfrow).copy worksheets("sheet2").range("a2")
worksheets("sheet1").range("a2:a" & halfrow).copy worksheets("sheet3").range("a2")
'copy remainder of names columns c
if (lastrow - 1) mod 2 = 0 then
moveamount = lastrow - halfrow + 2
else
moveamount = lastrow - halfrow + 3
end if
worksheets("sheet1").range("a" & moveamount & ":a" & lastrow).copy worksheets("sheet2").range("c2")
worksheets("sheet1").range("a" & moveamount & ":a" & lastrow).copy worksheets("sheet3").range("c2")
end sub
Office / Excel / Mac / Office 365 Home
- Get link
- X
- Other Apps
Comments
Post a Comment