this is regarding a macro in an excel.
While a combination of keys are pressed (ie the macro is triggered), I need to do some format changes to the columns 1 to 10 of the row that has the ActiveCell.
At the moment I have am selecting the entire row
ActiveCell.EntireRow.Select
However, I need to select only the row 1 to 10. I think it ought to be something like
ActiveCell.Range(1, 10).Select
But that does not work.
Just to be clear, I have read about
ActiveCell.Offset(5, -4).Select
But that is not going to work in my case. The ActiveCell could be any column of the row and hence a hardcoded offset is not going to help.
So, the excel gurus there, I am hoping this is a quick stuff, just that somehow I can't find the answer. Please help.
If it is always columns 1 to 10 (ie A to J) then this ought to work:
Range("A" & ActiveCell.Row & ":J" & ActiveCell.Row)
For example if the activecell is M14
then this will select the range A14:J14
. You can then format this how you like.
Hope this helps
Ok. This is what I did, and it works.
ActiveSheet.Range(Cells(ActiveCell.Row, 1), Cells(ActiveCell.Row, 10)).Select
In my mind this is sort of a hacky way. If there is anything better, please respond. Till we get something better, I guess this is the best answer for people who come looking for the anwer, after me.
这会奏效
Range("A" & ActiveCell.Row).Resize(1,10).select
if applicable.. spent alot of time to find, needed a more programmable - automated answer, for results - work on 1 line.
Dim N7 As String: N7 = RANGE("N7") 'workcell N7 shows eg: A:J
Intersect(Rows(ActiveCell.row), RANGE(N7).Columns).Select 'YES ANSWER
'other:
If application.Max(Intersect(Rows(ActiveCell.row), RANGE(N7).Columns)) > 0 Then
MsgBox "YES" & Space(10), vbQuestion ', "title": end if & vbCr &
Else: MsgBox "NO" & Space(10), vbQuestion: End If ', "title": end if & vbCr &
'Cells(ActiveCell.row, J6).OFFSET(, 1).RESIZE(, 6).Select 'YES: offset works on immediate cols for 1 row
'Cells(ActiveCell.row, J6).RESIZE(, 5).Select 'yes on 4 immediate cols for 1 row (row, col)
'Cells(ActiveCell.row, B5).select
workcell N7 has: =SUBSTITUTE(SUBSTITUTE(CELL("address",$A7),"$",""),ROW(),"")&":"&SUBSTITUTE(SUBSTITUTE(CELL("address",$J7),"$",""),ROW(),"")
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.