Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Return last row no. of column with blanks at top

I have column F that the data starts in F5 to F?
I want the last row number.
All these examples return F5, one errors out.

I can't believe I don't have an example in cheat sheet.

Thanks.
Howard

lrC = Sheets("Data").Cells(Rows.Count, 6).End(xlUp).Row

lrC = Range("F5:F" & Range("F5").End(xlDown)).Row

If WorksheetFunction.CountA(Cells) 0 Then
lrC = Cells.Find(What:="*", After:=[F5], _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
End If

MsgBox lrC
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Return last row no. of column with blanks at top

With Sheets("Data")
lrC = .Cells(.Rows.Count, 6).End(xlUp).Row
End With

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Return last row no. of column with blanks at top

On Thursday, December 5, 2013 1:26:51 PM UTC-8, GS wrote:
With Sheets("Data")

lrC = .Cells(.Rows.Count, 6).End(xlUp).Row

End With



--

Garry



Okay, got it, thanks Garry.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Return last row no. of column with blanks at top

On Thursday, December 5, 2013 3:35:20 PM UTC-8, Howard wrote:
On Thursday, December 5, 2013 1:26:51 PM UTC-8, GS wrote:

With Sheets("Data")




lrC = .Cells(.Rows.Count, 6).End(xlUp).Row




End With








--




Garry








Okay, got it, thanks Garry.


Well, I thought I had it.
I'm trying to set up an example to refer to that will define a mid column variable range and select it, one range on the sheet that has the code in its module, and one range on an adjacent sheet.

The commented out lines for rangeF work fine for the sheet with the code in its module. No need to mess with them.

The With Sheets("Data") lines for the rangeH error out after the Msgbox line. The msgbox displays the correct value for the last row on the Data sheet.
Any combination of the lines I have commented out or are using produces an error.

Thanks.
Howard

Option Explicit

Sub xx()
Dim rangeF As Range
Dim rangeH As Range
Dim lr As Long
Dim lrH As Long

'lr = Range("F" & Rows.Count).End(xlUp).Row
'MsgBox lr
'Set rangeF = Range("F6:F" & lr)
'rangeF.Select

With Sheets("Data")
lrH = .Cells(.Rows.Count, 8).End(xlUp).Row
MsgBox lrH
Set rangeH = Range("H6:H" & lrH)
'Set rangeH = Sheets("Data").Range("H6:H" & lrH)
rangeH.Select
'Sheets("Data").rangeH.Select
End With

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Return last row no. of column with blanks at top

Hi Howard,

Am Thu, 5 Dec 2013 22:23:38 -0800 (PST) schrieb Howard:

The commented out lines for rangeF work fine for the sheet with the code in its module. No need to mess with them.

The With Sheets("Data") lines for the rangeH error out after the Msgbox line. The msgbox displays the correct value for the last row on the Data sheet.
Any combination of the lines I have commented out or are using produces an error.


if you don't refer to a sheet the code takes the active sheet. To run
the code from each sheet use 2 With statements.
The code must be in a Standard Module
You can't select a range if the sheet is not active. But activate the
sheet and then select the range is not good. Better use Application.Goto

Sub xx()
Dim rangeF As Range
Dim rangeH As Range
Dim lr As Long
Dim lrH As Long

With Sheets("Sheet1")
lr = .Cells(.Rows.Count, "F").End(xlUp).Row
MsgBox lr
Set rangeF = .Range("F6:F" & lr)
Application.Goto rangeF
End With

With Sheets("Data")
lrH = .Cells(.Rows.Count, "H").End(xlUp).Row
MsgBox lrH
Set rangeH = .Range("H6:H" & lrH)
Application.Goto rangeH
End With

End Sub


Regards
Claus B.
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Return last row no. of column with blanks at top

On Friday, December 6, 2013 12:39:54 AM UTC-8, Claus Busch wrote:
Hi Howard,



Am Thu, 5 Dec 2013 22:23:38 -0800 (PST) schrieb Howard:



The commented out lines for rangeF work fine for the sheet with the code in its module. No need to mess with them.




The With Sheets("Data") lines for the rangeH error out after the Msgbox line. The msgbox displays the correct value for the last row on the Data sheet.


Any combination of the lines I have commented out or are using produces an error.




if you don't refer to a sheet the code takes the active sheet. To run

the code from each sheet use 2 With statements.

The code must be in a Standard Module

You can't select a range if the sheet is not active. But activate the

sheet and then select the range is not good. Better use Application.Goto



Sub xx()

Dim rangeF As Range

Dim rangeH As Range

Dim lr As Long

Dim lrH As Long



With Sheets("Sheet1")

lr = .Cells(.Rows.Count, "F").End(xlUp).Row

MsgBox lr

Set rangeF = .Range("F6:F" & lr)

Application.Goto rangeF

End With



With Sheets("Data")

lrH = .Cells(.Rows.Count, "H").End(xlUp).Row

MsgBox lrH

Set rangeH = .Range("H6:H" & lrH)

Application.Goto rangeH

End With



End Sub





Regards

Claus B.




Thanks Claus, and the small explanation is excellent.
I have copied it also to go with the code in my cheat sheet.

Thanks again.

Howard
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Return last row no. of column with blanks at top

I was going to reply similar to Claus for the With...End With block.

With Sheets("Data")
lrH = .Cells(.Rows.Count, "H").End(xlUp).Row
MsgBox lrH: Application.Goto .Range("H6:H" & lrH)
End With

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion



---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Return last row no. of column with blanks at top

On Friday, December 6, 2013 5:08:49 AM UTC-8, GS wrote:
I was going to reply similar to Claus for the With...End With block.



With Sheets("Data")

lrH = .Cells(.Rows.Count, "H").End(xlUp).Row

MsgBox lrH: Application.Goto .Range("H6:H" & lrH)

End With



--

Garry



Free usenet access at http://www.eternal-september.org

Classic VB Users Regroup!

comp.lang.basic.visual.misc

microsoft.public.vb.general.discussion







---

This email is free from viruses and malware because avast! Antivirus protection is active.

http://www.avast.com


Thanks, Garry.

I have the example and the snippet of info tucked away on my cheat sheet.
I have a hunch "Application.Goto .Range("H6:H" & lrH)" will be a pretty good tool.

Howard
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
Concatenate with carriage return- how to remove blanks? cindyc Excel Worksheet Functions 3 September 17th 08 10:31 PM
Return unique number, skip blanks lleytte Excel Worksheet Functions 6 June 26th 08 11:59 PM
Return Unique Records ... No Blanks Ken Excel Discussion (Misc queries) 4 September 6th 07 04:31 AM
selecting cells which contain formulas but return blanks hot dogs Excel Discussion (Misc queries) 3 September 12th 06 12:07 PM
Replace all non blanks in a column with column header hnyb1 Excel Discussion (Misc queries) 3 April 18th 06 05:39 PM


All times are GMT +1. The time now is 06:59 PM.

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"