#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Last column

Hi Guys,

I need to find the last column in a set of data.
Once the last column is found, I need to delete all data EXCEPT for the
last column (say column az) and except for the first Four columns (a to
d) ie all columns between d and bz needs to be deleted. Column d will
always be the same,but column bz is variable (ie could be column ay or
ax or anything.

Thanks

D



*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Last column

Hi Darin

Try this for the activesheet

Sub test()
Range(Cells(1, 5), Cells(1, Lastcol(ActiveSheet) - 1)).EntireColumn.Delete
End Sub

Function Lastcol(sh As Worksheet)
On Error Resume Next
Lastcol = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Column
On Error GoTo 0
End Function


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Darin Kramer" wrote in message
...
Hi Guys,

I need to find the last column in a set of data.
Once the last column is found, I need to delete all data EXCEPT for the
last column (say column az) and except for the first Four columns (a to
d) ie all columns between d and bz needs to be deleted. Column d will
always be the same,but column bz is variable (ie could be column ay or
ax or anything.

Thanks

D



*** Sent via Developersdex http://www.developersdex.com ***



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 397
Default Last column


Works perfectly!!!! Thanks so very much!


*** Sent via Developersdex http://www.developersdex.com ***
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Last column


Sub DeleteExcessData()
Dim rng As Range
Set rng = ActiveSheet.UsedRange
If Intersect(ActiveSheet.Columns("A:D"), rng) Is Nothing Then
MsgBox "Cant"
ElseIf rng.Columns.Count <= 5 Then
MsgBox "too narrow"
Else
rng.Columns(5).Resize(, rng.Columns.Count - 5).EntireColumn.Delete
End If

End Sub




--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Darin Kramer wrote :

Hi Guys,

I need to find the last column in a set of data.
Once the last column is found, I need to delete all data EXCEPT for
the last column (say column az) and except for the first Four columns
(a to d) ie all columns between d and bz needs to be deleted. Column
d will always be the same,but column bz is variable (ie could be
column ay or ax or anything.

Thanks

D



*** Sent via Developersdex http://www.developersdex.com ***

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
divide column(x) by column(y) to give column(x/y) in excel? James New Users to Excel 2 April 24th 23 11:46 AM
Referencing date column A & time column B to get info from column TVGuy29 Excel Discussion (Misc queries) 1 January 24th 08 09:50 PM
Return text in Column A if Column B and Column K match jeannie v Excel Worksheet Functions 4 December 13th 07 07:36 PM
Based on a condition in one column, search for a year in another column, and display data from another column in the same row look [email protected] Excel Discussion (Misc queries) 1 December 27th 06 05:47 PM
Divide Column A by Column B multiply Column C Stumped Excel Worksheet Functions 3 December 28th 05 05:51 AM


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