Store location of cell address to variable in VBA

后端 未结 3 1941
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 22:29

I\'m using VBA in Excel and I\'m using a function to find the first empty row then adding some values, after that I need to pass the address of the cell to another function but

3条回答
  •  一生所求
    2021-01-22 22:55

    I am a total "noob" at vba and learning by trying code snipits and routines that appear to to me to answer to a problem I am stuck on. When I tried the code posted by Vityata I encountered "Run-time error '424': Object Required at the following stmts:

        Set myCell = Sheet.Range(coltoSearch & i)
        Set FirstEmptyRow = Sheet.Range(coltoSearch & i + 1)
    

    Changing the stmts as follows resolved the errors for me:

        Set myCell = wks.Range(coltoSearch & i)
        Set FirstEmptyRow = wks.Range(coltoSearch & i + 1)
    

    I also added a Debug.Print stmt between the last End If and the End Function stmts so I could quickly see the result when testing as follows:

            End If
            Debug.Print "The 1st empty cell address is "; coltoSearch & i
        End Function
    

    If I have violated some posting rule, please accept my apology. Hopefully sharing this will avoid future confusion by others who use a similar learning process.

提交回复
热议问题