L
LHeld
Hello,
I'm trying to search for a word on a spreadsheet, in this case the word
"Label." I then want to copy everything from A1 to the row above that word
"Label" and paste it to a new spreadsheet. I've got everything worked out
except how to use the Find Result address in a new range. I'm sure it's
simple, so simple I can't find it in any tutorial. Currently I have to look
in each spreadsheet for the last row of the range I want to copy and type the
copy range manually into the code for each of the multiple spec sheet
spreadsheets I'm attempting to cut down into individual product spec sheets.
Perhaps somebody could point me in the right direction?
Thanks in advance to anybody.
My code, in case it helps:
activate application "Microsoft Excel"
repeat 10 times
tell application "Microsoft Excel"
set MainWkbk to active workbook
activate object worksheet "Sheet1"
set SpecSheetEnd to (find (range "1:100" of worksheet "Sheet1") what
"Label" after "1:1")
set SpecSheetRng to (get address SpecSheetEnd)
copy range range "A1:H88"
set newWkbk to make new workbook
tell newWkbk
activate object workbook newWkbk
tell sheet "Sheet1"
activate object worksheet "Sheet1" of newWkbk
set column width of range "A:A" of sheet "Sheet1" to 12 -- characters
(columns)
set column width of range "B:C" of sheet "Sheet1" to 4 -- characters
(columns)
set column width of range "D:E" of sheet "Sheet1" to 12 -- characters
(columns)
set column width of range "F:G" of sheet "Sheet1" to 4 -- characters
(columns)
set column width of range "H:H" of sheet "Sheet1" to 14 -- characters
(columns)
select sheet "Sheet1" of newWkbk
paste worksheet sheet "Sheet1" of newWkbk destination range "A1"
set StoryRow to (find (range "1:100" of worksheet "Sheet1") what "Label")
set row height of StoryRow to 35
set KeywordRow to (find (range "1:100" of worksheet "Sheet1") what "Key")
set row height of KeywordRow to 35
set IngredientRow to (find (range "1:100" of worksheet "Sheet1") what
"Ingredient")
set row height of IngredientRow to 35
set NutritionRow to (find (range "1:100" of worksheet "Sheet1") what
"Nutritional")
set row height of NutritionRow to 35
set WeightRow to (find (range "1:100" of worksheet "Sheet1") what
"Weight")
set row height of WeightRow to 35
set fc to (find (range "A:B" of worksheet "Sheet1") what "Weight")
make new horizontal page break at worksheet "Sheet1" of newWkbk ¬
with properties {location:range (get address fc)}
set fName to string value of range "D1" & " " & string value of range
"D3" & " " & string value of range "D4"
save workbook as newWkbk filename fName
tell newWkbk
activate object workbook MainWkbk
activate object worksheet "Sheet1" of MainWkbk
tell sheet "Sheet1"
close window 1
end tell
activate application "Microsoft Excel"
activate object workbook 1
tell workbook active workbook
tell sheet "Sheet1"
activate object worksheet "Sheet1" of active workbook
set SpecSheetEnd to (find (range "1:100" of worksheet "Sheet1") what
"Label" after "1:1")
set SpecSheetRng to "A1:H88"
delete range range SpecSheetRng shift shift up
end tell
end tell
end tell
end tell
end tell
end tell
end repeat
I'm trying to search for a word on a spreadsheet, in this case the word
"Label." I then want to copy everything from A1 to the row above that word
"Label" and paste it to a new spreadsheet. I've got everything worked out
except how to use the Find Result address in a new range. I'm sure it's
simple, so simple I can't find it in any tutorial. Currently I have to look
in each spreadsheet for the last row of the range I want to copy and type the
copy range manually into the code for each of the multiple spec sheet
spreadsheets I'm attempting to cut down into individual product spec sheets.
Perhaps somebody could point me in the right direction?
Thanks in advance to anybody.
My code, in case it helps:
activate application "Microsoft Excel"
repeat 10 times
tell application "Microsoft Excel"
set MainWkbk to active workbook
activate object worksheet "Sheet1"
set SpecSheetEnd to (find (range "1:100" of worksheet "Sheet1") what
"Label" after "1:1")
set SpecSheetRng to (get address SpecSheetEnd)
copy range range "A1:H88"
set newWkbk to make new workbook
tell newWkbk
activate object workbook newWkbk
tell sheet "Sheet1"
activate object worksheet "Sheet1" of newWkbk
set column width of range "A:A" of sheet "Sheet1" to 12 -- characters
(columns)
set column width of range "B:C" of sheet "Sheet1" to 4 -- characters
(columns)
set column width of range "D:E" of sheet "Sheet1" to 12 -- characters
(columns)
set column width of range "F:G" of sheet "Sheet1" to 4 -- characters
(columns)
set column width of range "H:H" of sheet "Sheet1" to 14 -- characters
(columns)
select sheet "Sheet1" of newWkbk
paste worksheet sheet "Sheet1" of newWkbk destination range "A1"
set StoryRow to (find (range "1:100" of worksheet "Sheet1") what "Label")
set row height of StoryRow to 35
set KeywordRow to (find (range "1:100" of worksheet "Sheet1") what "Key")
set row height of KeywordRow to 35
set IngredientRow to (find (range "1:100" of worksheet "Sheet1") what
"Ingredient")
set row height of IngredientRow to 35
set NutritionRow to (find (range "1:100" of worksheet "Sheet1") what
"Nutritional")
set row height of NutritionRow to 35
set WeightRow to (find (range "1:100" of worksheet "Sheet1") what
"Weight")
set row height of WeightRow to 35
set fc to (find (range "A:B" of worksheet "Sheet1") what "Weight")
make new horizontal page break at worksheet "Sheet1" of newWkbk ¬
with properties {location:range (get address fc)}
set fName to string value of range "D1" & " " & string value of range
"D3" & " " & string value of range "D4"
save workbook as newWkbk filename fName
tell newWkbk
activate object workbook MainWkbk
activate object worksheet "Sheet1" of MainWkbk
tell sheet "Sheet1"
close window 1
end tell
activate application "Microsoft Excel"
activate object workbook 1
tell workbook active workbook
tell sheet "Sheet1"
activate object worksheet "Sheet1" of active workbook
set SpecSheetEnd to (find (range "1:100" of worksheet "Sheet1") what
"Label" after "1:1")
set SpecSheetRng to "A1:H88"
delete range range SpecSheetRng shift shift up
end tell
end tell
end tell
end tell
end tell
end tell
end repeat