Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default How to set LastCell?

Hi,

You question doesn'r match the code you posted so here's a guess:-


Last used row in column C
LastRow = Cells(Cells.Rows.Count, "c").End(xlUp).Row

Last used column in Row 3
lastrow1 = Range("IV3").End(xlToLeft).Column

Mike

"jgmiddel" wrote:

In a worksheet I have an overview, in the row 3 are the headers. The
macro I have looks for the LastCell, but it sometimes happens one (or
more) of the columns is empty. The macro should check the last used
cell in row3 and then . How should I change this macro?

Sub AddNamesAndSort()
Dim PRng As Range
Dim Ccell As Range
Dim LastCell As Range
Dim PreviousPName As String
Set LastCell = Range("B65536").End(xlUp)
Set PRng = Range(Range("B5"), LastCell)

On Error Resume Next
For Each Ccell In PRng
If Ccell < "" And Ccell < PreviousPName Then
PreviousPName = Ccell
ActiveWorkbook.Names.Add Name:=Ccell,
RefersTo:=Ccell.CurrentRegion
Dim Rng As Range
Set Rng = Range(Range("calcsheet!B4").Text)
Dim UpDown As Integer
UpDown = Range("calcsheet!B2").Value
ActiveWorkbook.Worksheets("Overview").Sort.SortFie lds.Clear
ActiveWorkbook.Worksheets("Overview").Sort.SortFie lds.Add
Key:=Rng, _
SortOn:=xlSortOnValues, Order:=UpDown,
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("Overview").Sort
.SetRange Range(Ccell)
.Header = xlGuess
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
Next
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
UsedRange and LastCell feb08 Neal Zimm Excel Programming 5 February 5th 08 11:33 PM
lastcell Danilo[_2_] Excel Programming 2 January 19th 08 10:41 AM
LastCell Howard Excel Programming 5 March 6th 07 09:56 PM
Dynamic LastCell James Agostinho Excel Programming 4 February 22nd 04 09:08 PM
LastCell Function David Excel Programming 6 December 5th 03 02:51 PM


All times are GMT +1. The time now is 02:53 AM.

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

About Us

"It's about Microsoft Excel"