Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a macro to delete last 4 rows and last 2 columns which vary


I am using Excel to open up an html file from which I then need to
delete various rows and columns. It is always the first 3 rows and
first column. I must always delete the last 4 row and last 2 columns
but the actual row numbers and column letters can vary depending on how
many rows and columns are contained in the html file. I can use
Ctrl+end to go the last cell but this could vary each time the html
file is downloaded. Can anyone tell me the code which would cause a
macro to go to the last cell being used and delete 4 rows and 2 columns
from here.

Thanks

Shirley


--
Shirley Munro
------------------------------------------------------------------------
Shirley Munro's Profile: http://www.excelforum.com/member.php...nfo&userid=836
View this thread: http://www.excelforum.com/showthread...hreadid=401070

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using a macro to delete last 4 rows and last 2 columns which vary

Hi Shirley,

Try this

Sub deleteData()
Dim iLastRow As Long
Dim iLastCol As Long


iLastRow = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
iLastCol = Cells.Find(What:="*", _
After:=Range("A1"), _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious).Column

Columns(iLastCol - 1).Resize(, 2).Delete 'last 2
Columns(1).Delete 'first
Rows(iLastRow - 3).Resize(4).Delete 'last 4
Rows(1).Resize(3).Delete 'first 3
End Sub


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shirley Munro"
wrote in message
news:Shirley.Munro.1uod2b_1125569125.6012@excelfor um-nospam.com...

I am using Excel to open up an html file from which I then need to
delete various rows and columns. It is always the first 3 rows and
first column. I must always delete the last 4 row and last 2 columns
but the actual row numbers and column letters can vary depending on how
many rows and columns are contained in the html file. I can use
Ctrl+end to go the last cell but this could vary each time the html
file is downloaded. Can anyone tell me the code which would cause a
macro to go to the last cell being used and delete 4 rows and 2 columns
from here.

Thanks

Shirley


--
Shirley Munro
------------------------------------------------------------------------
Shirley Munro's Profile:

http://www.excelforum.com/member.php...nfo&userid=836
View this thread: http://www.excelforum.com/showthread...hreadid=401070



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Using a macro to delete last 4 rows and last 2 columns which vary


The code Bob has sent me works just fine but I am not sure how to record
this using the usual Tools, Macro, Record New Macro and making it
available in the Personal Macro Workbook

Shirley


--
Shirley Munro
------------------------------------------------------------------------
Shirley Munro's Profile: http://www.excelforum.com/member.php...nfo&userid=836
View this thread: http://www.excelforum.com/showthread...hreadid=401070

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Using a macro to delete last 4 rows and last 2 columns which vary

Shirley,

Go to record a macro as normal, saving to Personal.xls, but as soon as the
record starts, stop it. Then goto menu ToolsMacroMacros..., find the
macro, Edit and paste that code over it.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Shirley Munro"
wrote in message
news:Shirley.Munro.1uoo6d_1125583528.3199@excelfor um-nospam.com...

The code Bob has sent me works just fine but I am not sure how to record
this using the usual Tools, Macro, Record New Macro and making it
available in the Personal Macro Workbook

Shirley


--
Shirley Munro
------------------------------------------------------------------------
Shirley Munro's Profile:

http://www.excelforum.com/member.php...nfo&userid=836
View this thread: http://www.excelforum.com/showthread...hreadid=401070



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
Delete rows with more or less than 7 columns Keith New Users to Excel 8 May 22nd 09 10:26 AM
Sum of columns that vary in position gibsol Excel Worksheet Functions 5 August 17th 06 03:50 PM
Delete columns or rows Ivor Williams Excel Worksheet Functions 2 June 3rd 05 11:16 PM
subtotalling - # of columns vary MDC Excel Programming 1 July 22nd 03 04:43 PM
subtotalling where # of columns vary MC[_2_] Excel Programming 1 July 21st 03 04:17 AM


All times are GMT +1. The time now is 03:13 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"