[英]return a cell in the same row as activecell and first column of a selection in VBA
在此先感謝您的幫助。 我是VBA的新手,我需要選擇一個activecell的行標題-基本構建此代碼,這在VBA中似乎不起作用:
Dim C as range ("I4")
Dim R as C.CurrentRegion
cells(C.row,R.Columns(1)).Select
我不能使用C.End(xlToLeft)
因為我在左邊還有另一個表,盡管有一個空白列將2個表分開,但是此代碼跳到了左邊的表。 另外,表的第一列不是A,因此我無法對列號進行硬編碼。 非常感謝您的幫助! 西爾維亞
從您的帖子中可以理解的那一點,我想您正在
Intersect(ActiveCell.EntireRow, ActiveCell.CurrentRegion.Columns(1)).Select
要么
ActiveSheet.Cells(ActiveCell.row, ActiveCell.CurrentRegion.Columns(1).Column).Select
不使用“ helper” range
變量(例如C
或R
)
如果您需要使用它們,那么兩種選擇將變為:
Set C = ActiveCell
Set R = C.CurrentRegion
Intersect(C.EntireRow, R.Columns(1)).Select
要么
Set C = ActiveCell
Set R = C.CurrentRegion
ActiveSheet.Cells(C.row, R.Columns(1).Column).Select
但無論如何,最好不要選擇任何東西,而只是:
將其設置為某個range
變量:
Dim myCell as Range set myCell = Intersect(ActiveCell.EntireRow, ActiveCell.CurrentRegion.Columns(1))
然后使用它:
myCell.Font.ColorIndex = 3
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.