Make new folders with names from 2 columns from excel

Hello,
I am trying to automate the proccess of making a list of subfolders for peoples names
the names of the folders are comming from and Excel document with the surname in column A and first name in column B
I need the Surname first, then a Space, then the firstname for each folder

this is what i have come up with so far…


tell application "Finder"
 
          set _excel to choose file
          set _folder to choose folder
 
end tell
 
 
tell application "Microsoft Excel"
  open _excel
          set _surname to value of range "A1:A40" as list
          set _firstname to value of range "B1:B40" as list
  close active workbook
end tell
 
tell application "Finder"
          repeat with _foldername in _surname
  make new folder at folder _folder with properties {name:{(item 1 of _surname as text) & " " & (item 1 of _firstname as text)}}
          end repeat
end tell

This Succefully creates the 1st folder correctly but then it has an error


error "Finder got an error: The operation can't be completed because there is already an item with that name." number -48

In the Excel document the range of values can rang from 1-25 to 1-35 entries so i figured to just get values from 1-40. Maybe there is a way to only get the range of values with the number of populated cells ?

I guess the code doesnt repeat with item 2 of both lists and it tries to make the same folder name.

Any help is apreciated,
Thank you.

Model: iMac
AppleScript: 2.2.3
Browser: Safari 536.26.17
Operating System: Mac OS X (10.8)

Hello and Welcome to Macscripter!

I haven’t tested the code below, but I have a hunch that it will do what you want. I enumerate over the elements by their index value in the lists. Your problem was that you allways chose item #1 in the lists.

tell application "Finder"
	set _excel to choose file
	set _folder to choose folder
	
end tell

tell application "Microsoft Excel"
	open _excel
	set _surname to value of range "A1:A40" as list
	set _firstname to value of range "B1:B40" as list
	close active workbook
end tell

tell application "Finder"
	repeat with i from 1 to (count _surname)
		if item i of _surname is not "" and item i of _firstname is not "" then
			make new folder at folder _folder with properties {name:{(item i of _surname as text) & " " & (item i of _firstname as text)}}
		else
			exit repeat
		end if
	end repeat
end tell

Thank you !!!