How to pass a column of a selected range

2019-09-11 22:39发布

I did a little research and I found my question. The problem is it is written for some language called C that I am not familiar with. Not that I am all that familiar with VBA either but that is what I am working in and doing a very nice job of screwing things up. So in an effort to thwart my abilities to screw things up and instead make things work, how do I pass a sub range or column from a user selected column?

so in my example code I was trying to pass the entire first column of whatever was selected. Lets say user range was B34:D40, I want to pass B34:B40 such that arrange is B34:B40.

Sub initialsub (userrange as range)

Call secondfunction (userrange([],1)

end sub
----------------------------------------------------------------
function secondfunction (arrange as range) as long

some function that counts a variety of things in a single column

secondfunction = 45

end function

1条回答
别忘想泡老子
2楼-- · 2019-09-11 23:13

One way:

Sub dural()
    Dim FirstColumn As Range

    Set FirstColumn = Intersect(Selection(1).EntireColumn, Selection)
    MsgBox FirstColumn.Address
End Sub

enter image description here

Also:

Sub dural()
    MsgBox Selection.Columns(1).Address
End Sub

seems to do the trick.

查看更多
登录 后发表回答