Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Finding the last item in a group of ranges

I have some rows of data on a spreadsheet that are in groups of 4 fields
(columns) and have 5 sets across the screen so they're all visible at once.
Fileds are Amt, Date, # and Note. These "records" are each transactions
and they are in cells A5:D31. The next sets are in E5:H31, I5:L31, M5:P31
and Q5:531.

What I want to do is to find the last item in these rows, or the last
transaction.

This is the code I've used to find the first empty row in the cells:

Sub FirstEmpty() ' Finds first empty row on customer's sheet (card)
Set Srng = ActiveSheet.Range("A4:A31,E5:E31,I5:I31,M5:M31,Q5: Q31")
Set FoundCell = Srng.Find(what:="", LookIn:=xlFormulas,
searchorder:=xlByRows)
If Not FoundCell Is Nothing Then
FoundCell.Select ' Select empty cell
Exit Sub

I thought of using that and then just using an Offset line to go back one
line...but that won't work if I happen to be on the first line of a new
column.

Any help would be appreciated

Jonco


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Finding the last item in a group of ranges

maybe something like this, if all columns end in the same row

Sub test()
Dim lrow As Long
Dim Srng As Range
lrow = Range("a5000").End(xlUp).Row + 1

Set Srng = ActiveSheet.Range("A4:A" & lrow & ", E5:E" & lrow & ", I5:I" & lrow _
& ",M5:M" & lrow & ", Q5:Q" & lrow)

End Sub
--


Gary


"jonco" wrote in message
...
I have some rows of data on a spreadsheet that are in groups of 4 fields
(columns) and have 5 sets across the screen so they're all visible at once.
Fileds are Amt, Date, # and Note. These "records" are each transactions and
they are in cells A5:D31. The next sets are in E5:H31, I5:L31, M5:P31 and
Q5:531.

What I want to do is to find the last item in these rows, or the last
transaction.

This is the code I've used to find the first empty row in the cells:

Sub FirstEmpty() ' Finds first empty row on customer's sheet (card)
Set Srng = ActiveSheet.Range("A4:A31,E5:E31,I5:I31,M5:M31,Q5: Q31")
Set FoundCell = Srng.Find(what:="", LookIn:=xlFormulas, searchorder:=xlByRows)
If Not FoundCell Is Nothing Then
FoundCell.Select ' Select empty cell
Exit Sub

I thought of using that and then just using an Offset line to go back one
line...but that won't work if I happen to be on the first line of a new
column.

Any help would be appreciated

Jonco



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Finding the last item in a group of ranges

Depends how you fill things in. Do you do it by column or by row. That is to
say do you do all of A:D then E:H or do you do all of row 5 then all of row 6
then... From your descrition it sounds like by column. The answer will be
heavily dependant on that however. Your find code is not bad but you really
want to look Backwards from the first record until you find a populated
Cell...

Sub FirstEmpty() ' Finds first empty row on customer's sheet (card)
Set Srng = ActiveSheet.Range("A4:A31,E5:E31,I5:I31,M5:M31,Q5: Q31")
Set FoundCell = Srng.Find(what:="*", LookIn:=xlFormulas,
searchorder:=xlByRows, SearchDirection:=xlPrevious)
If FoundCell Is Nothing Then
ActiveSheet.Range("A4").select
Else
if FoundCell.row = 31
foundcell.select
msgbox "startnewcolumn by offsetting from here"
else
foundcell.offset(0,1).select
Exit Sub

It should be something like that...

--
HTH...

Jim Thomlinson


"jonco" wrote:

I have some rows of data on a spreadsheet that are in groups of 4 fields
(columns) and have 5 sets across the screen so they're all visible at once.
Fileds are Amt, Date, # and Note. These "records" are each transactions
and they are in cells A5:D31. The next sets are in E5:H31, I5:L31, M5:P31
and Q5:531.

What I want to do is to find the last item in these rows, or the last
transaction.

This is the code I've used to find the first empty row in the cells:

Sub FirstEmpty() ' Finds first empty row on customer's sheet (card)
Set Srng = ActiveSheet.Range("A4:A31,E5:E31,I5:I31,M5:M31,Q5: Q31")
Set FoundCell = Srng.Find(what:="", LookIn:=xlFormulas,
searchorder:=xlByRows)
If Not FoundCell Is Nothing Then
FoundCell.Select ' Select empty cell
Exit Sub

I thought of using that and then just using an Offset line to go back one
line...but that won't work if I happen to be on the first line of a new
column.

Any help would be appreciated

Jonco



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 53
Default Finding the last item in a group of ranges

Thanks guys. I got it working. You guys are great!

Jonco

"jonco" wrote in message
...
I have some rows of data on a spreadsheet that are in groups of 4 fields
(columns) and have 5 sets across the screen so they're all visible at once.
Fileds are Amt, Date, # and Note. These "records" are each transactions
and they are in cells A5:D31. The next sets are in E5:H31, I5:L31, M5:P31
and Q5:531.

What I want to do is to find the last item in these rows, or the last
transaction.

This is the code I've used to find the first empty row in the cells:

Sub FirstEmpty() ' Finds first empty row on customer's sheet (card)
Set Srng = ActiveSheet.Range("A4:A31,E5:E31,I5:I31,M5:M31,Q5: Q31")
Set FoundCell = Srng.Find(what:="", LookIn:=xlFormulas,
searchorder:=xlByRows)
If Not FoundCell Is Nothing Then
FoundCell.Select ' Select empty cell
Exit Sub

I thought of using that and then just using an Offset line to go back one
line...but that won't work if I happen to be on the first line of a new
column.

Any help would be appreciated

Jonco



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
Finding an item in a list & returning a specific value SBW Excel Worksheet Functions 7 April 20th 09 09:54 PM
Finding a specific item between two sheets. Dan C.[_2_] Excel Discussion (Misc queries) 2 January 27th 09 03:06 PM
finding more than one item sujensen Excel Discussion (Misc queries) 1 April 26th 08 02:30 AM
Finding current week and if any item has somthing due Robert Brown Excel Worksheet Functions 2 July 19th 06 02:15 PM
Group Boxes - selecting more than one item Katie-Baughman Excel Discussion (Misc queries) 3 May 13th 05 06:15 PM


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