ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Activate Cells (https://www.excelbanter.com/excel-programming/353008-activate-cells.html)

gabe

Activate Cells
 
Hello,

I am trying to use the following code but for some reason it isn't working?
Can you all try it and maybe tell me what I am doing wrong? Everything works
up until it is supposed to select the cells to the right. As you would if you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub

Don Guillett

Activate Cells
 
try
Sub copylastcell()
Sheets("mysheet").Range("a2").End(xlDown). _
End(xlToRight).Copy ActiveCell

End Sub

--
Don Guillett
SalesAid Software

"Gabe" wrote in message
...
Hello,

I am trying to use the following code but for some reason it isn't
working?
Can you all try it and maybe tell me what I am doing wrong? Everything
works
up until it is supposed to select the cells to the right. As you would if
you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you
make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub




gabe

Activate Cells
 
It keeps deleting the value in A2? I tried the sub by its self, and it
doesn't do anything?

"Don Guillett" wrote:

try
Sub copylastcell()
Sheets("mysheet").Range("a2").End(xlDown). _
End(xlToRight).Copy ActiveCell

End Sub

--
Don Guillett
SalesAid Software

"Gabe" wrote in message
...
Hello,

I am trying to use the following code but for some reason it isn't
working?
Can you all try it and maybe tell me what I am doing wrong? Everything
works
up until it is supposed to select the cells to the right. As you would if
you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you
make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub





Don Guillett

Activate Cells
 
Is your source sheet named mysheet?

What this is doing is - From anywhere in the workbook it will copy cell a2
end(xldown) end(xltoright) to the cell where your cursor is.

What did you do?

--
Don Guillett
SalesAid Software

"Gabe" wrote in message
...
It keeps deleting the value in A2? I tried the sub by its self, and it
doesn't do anything?

"Don Guillett" wrote:

try
Sub copylastcell()
Sheets("mysheet").Range("a2").End(xlDown). _
End(xlToRight).Copy ActiveCell

End Sub

--
Don Guillett
SalesAid Software

"Gabe" wrote in message
...
Hello,

I am trying to use the following code but for some reason it isn't
working?
Can you all try it and maybe tell me what I am doing wrong? Everything
works
up until it is supposed to select the cells to the right. As you would
if
you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you
make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub







sebastienm

Activate Cells
 
Hi,
This code would work better than the {DOWN} in your case ie dealing with
grouped rows:
'---------------------------------
Sub Macro1()
Dim rg As Range, rg2 As Range

Set rg = ActiveCell

'1 - get the bottom column starting at rg
Set rg2 = Range(rg, rg.Parent.Cells(rg.Parent.Rows.Count, rg.Column))
'visible cells only
Set rg2 = rg2.SpecialCells(xlCellTypeVisible)

'2 - get the bottom col starting just bellow rg
Set rg = Range(rg.Offset(1, 0), rg.Parent.Cells(rg.Parent.Rows.Count,
rg.Column))

'3 - intersect the 2 ranges and keep first cell
Set rg = Application.Intersect(rg, rg2).Cells(1)

rg.Select
End Sub
'-----------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Gabe" wrote:

Hello,

I am trying to use the following code but for some reason it isn't working?
Can you all try it and maybe tell me what I am doing wrong? Everything works
up until it is supposed to select the cells to the right. As you would if you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub


gabe

Activate Cells
 
Sure enough that worked! Awesome, thanks again for showing me that it would
of taken forever to figure that out. The USAF thanks you too Sébastien.

"sebastienm" wrote:

Hi,
This code would work better than the {DOWN} in your case ie dealing with
grouped rows:
'---------------------------------
Sub Macro1()
Dim rg As Range, rg2 As Range

Set rg = ActiveCell

'1 - get the bottom column starting at rg
Set rg2 = Range(rg, rg.Parent.Cells(rg.Parent.Rows.Count, rg.Column))
'visible cells only
Set rg2 = rg2.SpecialCells(xlCellTypeVisible)

'2 - get the bottom col starting just bellow rg
Set rg = Range(rg.Offset(1, 0), rg.Parent.Cells(rg.Parent.Rows.Count,
rg.Column))

'3 - intersect the 2 ranges and keep first cell
Set rg = Application.Intersect(rg, rg2).Cells(1)

rg.Select
End Sub
'-----------------------------------------------------
--
Regards,
Sébastien
<http://www.ondemandanalysis.com


"Gabe" wrote:

Hello,

I am trying to use the following code but for some reason it isn't working?
Can you all try it and maybe tell me what I am doing wrong? Everything works
up until it is supposed to select the cells to the right. As you would if you
were to use Ctrl+Shift+Right Arrow keys. Once it goes down, how do you make
the current cell that it selects active?

Sub Macro1()
Sheets("Sheet1").Select
Range("A2").Activate
'
Application.SendKeys "{DOWN}"
'
Range(Selection, Selection.End(xlToRight)).Copy
End Sub



All times are GMT +1. The time now is 12:35 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com