Read Excel throw cant make text item into type strin

Hi,

I have Excel like below:

A | B
Texture | Brand
ZERO | Test

2 columns A and B with header Texture and Brand. I have one line data Zero and Test.

Below is my apple script:

repeat with i from 2 to CountTotalrow
		set CurrentCell to get address of cell i of column CountTotalColumn
		if CurrentCell = "" then
			set ExitRepeat to 1
			exit repeat
		end if
		set CurrentRowInfo to string value of range ("A" & i & ":" & CurrentCell)
		set ToOpenMaster to item 2 of item 1 of CurrentRowInfo
		set AppleScript's text item delimiters to "_"
		set VariantName to text item 1 of ToOpenMaster as string
		--display dialog VariantName
		set BrandName to text item 2 of ToOpenMaster as string
		display dialog BrandName

When I run the script im getting

Any idea where i did wrong.

What is the intended functionality of the script?

Some issues it what you posted:

“CountTotalrow” isn’t defined
“CountTotalColumn” isn’t defined
There is no “end repeat”

I assume that’s all because you didn’t post all the relevant code.

“set ExitRepeat to 1” doesn’t accomplish anything in the script
you should be using “item” instead of “text item” to set “VariantName” and “BrandName”

Your error message occurs as follows:
CurrentRowInfo gets set to: {{“ZERO”, “Test”}}
A list of one item, that item being a list of 2 items.

“ToOpenMaster” is set to “item 2 of item 1” of “CurrentRowInfo”, which is the word “Test”

So “ToOpenMaster” = “Test”

Then you have this line:

set BrandName to text item 2 of ToOpenMaster as string

You can not get “item 2” of the word “test.”

So I suspect you’re looking for something like this:


set CountTotalrow to 2
set CountTotalColumn to 2

tell application "Microsoft Excel"
	repeat with i from 2 to CountTotalrow
		set CurrentCell to get address of cell i of column CountTotalColumn
		if CurrentCell = "" then
			set ExitRepeat to 1
			exit repeat
		end if
		set CurrentRowInfo to string value of range ("A" & i & ":" & CurrentCell)
		set ToOpenMaster to item 1 of CurrentRowInfo --< This line edited.
		set AppleScript's text item delimiters to "_"
		set VariantName to text item 1 of ToOpenMaster as string
		--display dialog VariantName
		set BrandName to text item 2 of ToOpenMaster as string
		display dialog BrandName
	end repeat
end tell

Depending on your objective, this may be shorter code to get there:

tell application "Microsoft Excel" to tell the active sheet of the active workbook to set spreadsheetData to the value of the used range
repeat with i from 2 to count of spreadsheetData
	tell item i of spreadsheetData to set {VariantName, BrandName} to {item 1, item 2}
	display dialog BrandName
end repeat

** - Minor edit made to put “item i” inside the “tell” for brevity and clarity