Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 54
Default Last used cell problem

I am using Excel 2003 and have imported and external data to Sheet1. Once the
data is imported, using code the data is sorted then subtotaled by the values
in column D. What is happening is that in the initial import the last cell is
O3534. After the sort and subtotal, the last cell is O3778. Since I am using
a range to do the sort and subtotal and formatting, I want the range to point
to the last cell of any new imported data not the last cell used, which is
O338 from the subtotal list. I have tried deleting all the rows and columns
following the imported data row, the clear contents option but if I use the
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address) code still shows
the last cell is O3778. What I want to do is find the last used cell
containing data based on the last imported data, and delete all other cells
that have been used. Below is the code that is being used.
Thank you.

Private Sub Refre****()
'Prompt user for new import data source
With ActiveSheet
Range("O3").Select
ActiveCell.EntireColumn.Delete
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Columns("O").ColumnWidth = "5.57"
Range("A2").Select
End With
End Sub


Private Sub FindSetRange()

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngfulldata.Name = "FullData"

End Sub


Private Sub TrimIt()
Dim myCell As Range
For Each myCell In Range("FullData")
myCell.Formula = RTrim(myCell.Formula)
Next myCell

End Sub

Private Sub SortIt()

'set display alerts off for now
'turned back on at end of SubTtl procedure

Application.DisplayAlerts = False
Dim rngSortData As Range
Set rngSortData = Range("A1:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngSortData.Name = "SortData"

Worksheets(1).Range("SortData").Select

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

Private Sub SubTtl()

Range("FullData").Select
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(12), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A94").Select

'Turn the display alerts back on
Application.DisplayAlerts = True

Range("A1:O1").Select
With Selection
.Columns.AutoFit
End With

End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
dan dan is offline
external usenet poster
 
Posts: 866
Default Last used cell problem

Why not use:

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.CurrentRegion.Address)

instead of

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)

Dan

"Billy B" wrote:

I am using Excel 2003 and have imported and external data to Sheet1. Once the
data is imported, using code the data is sorted then subtotaled by the values
in column D. What is happening is that in the initial import the last cell is
O3534. After the sort and subtotal, the last cell is O3778. Since I am using
a range to do the sort and subtotal and formatting, I want the range to point
to the last cell of any new imported data not the last cell used, which is
O338 from the subtotal list. I have tried deleting all the rows and columns
following the imported data row, the clear contents option but if I use the
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address) code still shows
the last cell is O3778. What I want to do is find the last used cell
containing data based on the last imported data, and delete all other cells
that have been used. Below is the code that is being used.
Thank you.

Private Sub Refre****()
'Prompt user for new import data source
With ActiveSheet
Range("O3").Select
ActiveCell.EntireColumn.Delete
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Columns("O").ColumnWidth = "5.57"
Range("A2").Select
End With
End Sub


Private Sub FindSetRange()

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngfulldata.Name = "FullData"

End Sub


Private Sub TrimIt()
Dim myCell As Range
For Each myCell In Range("FullData")
myCell.Formula = RTrim(myCell.Formula)
Next myCell

End Sub

Private Sub SortIt()

'set display alerts off for now
'turned back on at end of SubTtl procedure

Application.DisplayAlerts = False
Dim rngSortData As Range
Set rngSortData = Range("A1:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngSortData.Name = "SortData"

Worksheets(1).Range("SortData").Select

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

Private Sub SubTtl()

Range("FullData").Select
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(12), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A94").Select

'Turn the display alerts back on
Application.DisplayAlerts = True

Range("A1:O1").Select
With Selection
.Columns.AutoFit
End With

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 320
Default Last used cell problem

Sub GetRealLastCelAddress()
On Error Resume Next
xc = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByColumns,
SearchDirection:=xlPrevious).Column
xr = Cells.Find("*", After:=Range("A1"), SearchOrder:=xlByRows,
SearchDirection:=xlPrevious).Row
MsgBox Cells(xr, xc).Address
End Sub

Bob Umlas
Excel MVP

"Dan" wrote in message
...
Why not use:

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.CurrentRegion.Address)

instead of

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)

Dan

"Billy B" wrote:

I am using Excel 2003 and have imported and external data to Sheet1. Once
the
data is imported, using code the data is sorted then subtotaled by the
values
in column D. What is happening is that in the initial import the last
cell is
O3534. After the sort and subtotal, the last cell is O3778. Since I am
using
a range to do the sort and subtotal and formatting, I want the range to
point
to the last cell of any new imported data not the last cell used, which
is
O338 from the subtotal list. I have tried deleting all the rows and
columns
following the imported data row, the clear contents option but if I use
the
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address) code still
shows
the last cell is O3778. What I want to do is find the last used cell
containing data based on the last imported data, and delete all other
cells
that have been used. Below is the code that is being used.
Thank you.

Private Sub Refre****()
'Prompt user for new import data source
With ActiveSheet
Range("O3").Select
ActiveCell.EntireColumn.Delete
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Columns("O").ColumnWidth = "5.57"
Range("A2").Select
End With
End Sub


Private Sub FindSetRange()

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngfulldata.Name = "FullData"

End Sub


Private Sub TrimIt()
Dim myCell As Range
For Each myCell In Range("FullData")
myCell.Formula = RTrim(myCell.Formula)
Next myCell

End Sub

Private Sub SortIt()

'set display alerts off for now
'turned back on at end of SubTtl procedure

Application.DisplayAlerts = False
Dim rngSortData As Range
Set rngSortData = Range("A1:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngSortData.Name = "SortData"

Worksheets(1).Range("SortData").Select

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

Private Sub SubTtl()

Range("FullData").Select
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(12),
_
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A94").Select

'Turn the display alerts back on
Application.DisplayAlerts = True

Range("A1:O1").Select
With Selection
.Columns.AutoFit
End With

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Last used cell problem

See
http://www.rondebruin.nl/last.htm

--

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm




"Billy B" wrote in message ...
I am using Excel 2003 and have imported and external data to Sheet1. Once the
data is imported, using code the data is sorted then subtotaled by the values
in column D. What is happening is that in the initial import the last cell is
O3534. After the sort and subtotal, the last cell is O3778. Since I am using
a range to do the sort and subtotal and formatting, I want the range to point
to the last cell of any new imported data not the last cell used, which is
O338 from the subtotal list. I have tried deleting all the rows and columns
following the imported data row, the clear contents option but if I use the
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address) code still shows
the last cell is O3778. What I want to do is find the last used cell
containing data based on the last imported data, and delete all other cells
that have been used. Below is the code that is being used.
Thank you.

Private Sub Refre****()
'Prompt user for new import data source
With ActiveSheet
Range("O3").Select
ActiveCell.EntireColumn.Delete
Range("A3").Select
Selection.QueryTable.Refresh BackgroundQuery:=False

Columns("O").ColumnWidth = "5.57"
Range("A2").Select
End With
End Sub


Private Sub FindSetRange()

Set rngfulldata = Range("A2:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngfulldata.Name = "FullData"

End Sub


Private Sub TrimIt()
Dim myCell As Range
For Each myCell In Range("FullData")
myCell.Formula = RTrim(myCell.Formula)
Next myCell

End Sub

Private Sub SortIt()

'set display alerts off for now
'turned back on at end of SubTtl procedure

Application.DisplayAlerts = False
Dim rngSortData As Range
Set rngSortData = Range("A1:" & _
ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell) .Address)
rngSortData.Name = "SortData"

Worksheets(1).Range("SortData").Select

Selection.Sort Key1:=Range("D2"), Order1:=xlAscending, Header:=xlYes, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal

End Sub

Private Sub SubTtl()

Range("FullData").Select
Selection.Subtotal GroupBy:=4, Function:=xlSum, TotalList:=Array(12), _
Replace:=True, PageBreaks:=False, SummaryBelowData:=True
ActiveSheet.Outline.ShowLevels RowLevels:=2
Range("A94").Select

'Turn the display alerts back on
Application.DisplayAlerts = True

Range("A1:O1").Select
With Selection
.Columns.AutoFit
End With

End Sub

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
Cell Underline problem underlines across width of cell tshoop7 Excel Worksheet Functions 1 July 24th 08 12:18 AM
Very Basic Problem - Merged Cell Equals Contents of a Single Cell jollynicechap Excel Worksheet Functions 3 December 29th 06 08:16 PM
Cell problem Patrick Excel Worksheet Functions 3 March 29th 05 03:33 PM
problem with cell reference in =sum(offset(cell reference,x,y,z,a)). Want cell ref to be variable. [email protected] Excel Worksheet Functions 2 December 11th 04 12:05 AM
cell problem Libby Excel Programming 2 September 10th 04 04:35 PM


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