在单元格上使用偏移

时间:2018-08-05 16:59:07

标签: vba excel-vba

如果我在Excel范围内有一个单元格,该如何相对于该单元格使用偏移功能?

Excel我不喜欢cell.offset(-1,0),因为偏移量仅用于范围。

我尝试了namedrange.cell.offset(-1,0),但这显然是不对的。

Set r = range("named_range")
For Each cell In r
If IsEmpty(cell) Then

  j = j + 1
  n = 1

While IsEmpty(cell.Offset(-n, 0))
  n = n + 1
Wend

所以我的问题是cell.offset(-n,0)部分

谢谢

1 个答案:

答案 0 :(得分:0)

  

应用定义的错误

我唯一可以重复您的问题的方法是,当偏移值导致无效的单元格位置时。最低的行值为[[(ive, searching), (searching, right), (right, word), (word, thank), (thank, breather)], [(i, promise), (promise, wont), (wont, take), (take, help), (help, granted), (granted, fulfil), (fulfil, promise)], [(you, wonderful), (wonderful, blessing), (blessing, time)]] [[(free, entry), (entry, 2), (2, wkly), (wkly, comp), (comp, win), (win, fa), (fa, cup), (cup, final), (final, tkts), (tkts, 21st), (21st, may), (may, 2005)], [(text, fa), (fa, 87121), (87121, receive), (receive, entry), (entry, questionstd), (questionstd, txt), (txt, ratetcs), (ratetcs, apply), (apply, 08452810075over18s)]] [[(nah, dont), (dont, think), (think, go), (go, usf), (usf, life), (life, around), (around, though)]] [[(even, brother), (brother, like), (like, speak), (speak, me)], [(they, treat), (treat, like), (like, aid), (aid, patent)]] 。我猜您的偏移量会将您带到无效行(def toFlatListBigram(fullCorpus): flatListBigram = fullCorpus['bigrams'].apply( lambda row: [np.concatenate(x) for x in row]) return flatListBigram ),这会给您带来错误。

如果您在1并使用0,则会出现错误。 第1行上方没有行。

类似地, A列之前没有任何列。 Range(“ A1”)。Offset(0,-1)也会产生相同的错误。