![]() |
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 |
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 |
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 |
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 |
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