Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Valerie
 
Posts: n/a
Default Macro for cell selection starting with Last Cell

I want to go to the last cell on the worksheet and select it along with 16
prior cells in order to delete the last 16 rows of the worksheet at once
instead of deleting one row at a time.

Thanks!
Valerie
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Macro for cell selection starting with Last Cell

I used column A to find the last row of the worksheet.

Dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
if lastrow < 16 then
msgbox "are you on the correct sheet?"
exit sub
end if

.rows(lastrow -16 + 1 & ":" & .rows.count).delete
end with


Valerie wrote:

I want to go to the last cell on the worksheet and select it along with 16
prior cells in order to delete the last 16 rows of the worksheet at once
instead of deleting one row at a time.

Thanks!
Valerie


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Valerie
 
Posts: n/a
Default Macro for cell selection starting with Last Cell

Works! Thanks! I've always been curious - what does the "Dim" mean as far
as how it works, what it's function is, what is it telling XL to do?

"Dave Peterson" wrote:

I used column A to find the last row of the worksheet.

Dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
if lastrow < 16 then
msgbox "are you on the correct sheet?"
exit sub
end if

.rows(lastrow -16 + 1 & ":" & .rows.count).delete
end with


Valerie wrote:

I want to go to the last cell on the worksheet and select it along with 16
prior cells in order to delete the last 16 rows of the worksheet at once
instead of deleting one row at a time.

Thanks!
Valerie


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Dave Peterson
 
Posts: n/a
Default Macro for cell selection starting with Last Cell

It tells excel that you're creating a variable. In this case, I declared a
variable as Long (a counting number--no fractions).

Declaring the variables and telling excel that you want to declare variables go
hand in hand.

Option Explict

at the top of the module means that I have to declare all the variables I use.

Then if I did this:

option explicit
sub test()
dim firstrow as long
firstrow = 0
firstrow = fristrow + 1
end sub

wouldn't get close to running. (Fristrow is spelled incorrectly and excel knows
it's not a variable, since I didn't declare it.)


By declaring the variables, it'll make your code easier to debug/maintain.

And you'll even get excel's intellisense to help out.

try this:
Dim wks as worksheet
'then type wks. (with that dot)
wks.

You'll see a list of all the things that you could type next that can be used
with worksheet objects.




Valerie wrote:

Works! Thanks! I've always been curious - what does the "Dim" mean as far
as how it works, what it's function is, what is it telling XL to do?

"Dave Peterson" wrote:

I used column A to find the last row of the worksheet.

Dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
if lastrow < 16 then
msgbox "are you on the correct sheet?"
exit sub
end if

.rows(lastrow -16 + 1 & ":" & .rows.count).delete
end with


Valerie wrote:

I want to go to the last cell on the worksheet and select it along with 16
prior cells in order to delete the last 16 rows of the worksheet at once
instead of deleting one row at a time.

Thanks!
Valerie


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Valerie
 
Posts: n/a
Default Macro for cell selection starting with Last Cell

Thanks, Dave! You guys know so much - I love this resource!

"Dave Peterson" wrote:

It tells excel that you're creating a variable. In this case, I declared a
variable as Long (a counting number--no fractions).

Declaring the variables and telling excel that you want to declare variables go
hand in hand.

Option Explict

at the top of the module means that I have to declare all the variables I use.

Then if I did this:

option explicit
sub test()
dim firstrow as long
firstrow = 0
firstrow = fristrow + 1
end sub

wouldn't get close to running. (Fristrow is spelled incorrectly and excel knows
it's not a variable, since I didn't declare it.)


By declaring the variables, it'll make your code easier to debug/maintain.

And you'll even get excel's intellisense to help out.

try this:
Dim wks as worksheet
'then type wks. (with that dot)
wks.

You'll see a list of all the things that you could type next that can be used
with worksheet objects.




Valerie wrote:

Works! Thanks! I've always been curious - what does the "Dim" mean as far
as how it works, what it's function is, what is it telling XL to do?

"Dave Peterson" wrote:

I used column A to find the last row of the worksheet.

Dim LastRow as long
with activesheet
lastrow = .cells(.rows.count,"A").end(xlup).row
if lastrow < 16 then
msgbox "are you on the correct sheet?"
exit sub
end if

.rows(lastrow -16 + 1 & ":" & .rows.count).delete
end with


Valerie wrote:

I want to go to the last cell on the worksheet and select it along with 16
prior cells in order to delete the last 16 rows of the worksheet at once
instead of deleting one row at a time.

Thanks!
Valerie

--

Dave Peterson


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can a macro be made to run on entering or leaving a cell? Dave Lister Excel Discussion (Misc queries) 1 December 3rd 05 07:11 PM
Macro code for dropping to next empty cell JB2010 Excel Discussion (Misc queries) 4 November 3rd 05 01:35 PM
move to another cell within a subtotal report within a macro NoelH Excel Worksheet Functions 1 August 31st 05 03:02 PM
Cell Selection after "Enter" Synectica Excel Discussion (Misc queries) 6 August 29th 05 09:55 PM
in cell editing macro ynissel Excel Discussion (Misc queries) 2 July 27th 05 07:28 PM


All times are GMT +1. The time now is 03:31 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"