質問

I have an Excel spreadsheet that contains data similar to the following: enter image description here

I want to do a certain set of operations for each category for each of the names. I am guaranteed to have an empty cell before each new set of categories (but not necessarily the names), so when I iterate over the names, I do the following to find out what the last category row is:

rowNum = sheetVariable.Cells(theName.Row + 1, 2).End(xlDown).Row

This works great except that if there is only one category for a name (such as for name4 in the example image), it hops down to the next category of the next name.

Is there a way to do this so that it also works for the case where there is only one category row for a person?

役に立ちましたか?

解決

Check to see if

sheetVariable.Cells(theName.Row + 2, 2) 

is empty: if not then you can use the .End(xlDown) approach, otherwise the last row is theName.Row + 1

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top