Error message " undefined method `[]' for nil:NilClass (NoMethodError) ". Please help ASAP

Below is my ruby capybara code. When executing using cucumber I get the
error “undefined method `[]’ for nil:NilClass (NoMethodError)”. please
help

require ‘rubyXL’
require ‘roo’
workbook = Roo::Spreadsheet.open(file_name)
workbook1 = RubyXL::Parser.parse(file_name)

workbook.default_sheet=‘Search_plan’
worksheet1 = workbook1[‘Search_plan’]
j = [ ]
for j in (1…workbook.last_row).step(2)
print j
d=j

for k in workbook.first_column..workbook.last_column

  if k==1

    choose("lookupSearch", :option => "Plan")
    fill_in "searchInput", :with => workbook.cell(j,k)
    find(:xpath, '//*[@id="searchicon"]').click

  else
    elementXpath=""

    print "\n"

    findXpath=page.find('label', text: workbook.cell(j,k), :match =>

:prefer_exact).path
splitXpath = [ ]
splitXpath=findXpath.split("/")
count1 = [ ]
count1=splitXpath.count
value1 = [ ]
value1=splitXpath.at(count1-2)
labelNum = [ ]
labelNum=value1.match(/(\d+)/)

elementNum = [ ]
    elementNum=labelNum[1].to_i+1

    for maxnum in 1..splitXpath.count-3
      elementXpath=elementXpath + "/" + splitXpath[maxnum]
    end
    elementXpath=elementXpath + "/div[" + elementNum.to_s + "]"
    elementXpath=elementXpath + "/" + splitXpath.at(count1-1)
      finalElementXpath = [ ]

     finalElementXpath=elementXpath.sub("label","span")

    if (workbook.cell(j+1,k) == (find(:xpath,

finalElementXpath).native.text))
print “—#{workbook.cell(j+1,k)}–value — exist--------for
#{workbook.cell(j,k)} ------------ \n”
worksheet1.sheet_data[d][k-1].change_fill (‘008000’)
else
print “-----object #{workbook.cell(j+1,k)} – doesnt
exist—for #{workbook.cell(j,k)} --------- \n”
worksheet1.sheet_data[d][k-1].change_fill (‘ff0000’)
end
end
end

end
workbook1.write(file_name)