Find Last Data In Columns

nehpets12

Active Member
Joined
Feb 22, 2002
Messages
453
I have 8 columns B to I in these I have either 1 or 0.5 I need a macro that that goes down to the last entry in any of these columns and selects the entry in I.

I only need to find this data in columns B C G H I

I am setting it up to create a print area A1 to the active cell I hope this is clear.
 
AJ,

I think he is looking for the last row with data in any of the columns B to I, and he's going to Column I to be able to set a print area of A1 to I(Last row with data in Column B to Column I) to ba able to set the print area to include all data.

Am I right?
 
Upvote 0

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
I only need to find the end data in "b" "c" "g" "h" or "i" I have data in columns D E F but I want ti ignor the data in these columns hope this is clearer

Thanks for your help in advance
 
Upvote 0
Here's another try.
Is this right???
Regardless of any other column on the sheet we're only interested in finding out which of columns B, C, G, H and I has the greatest row number with data in it, and then selecting the cell in column I that corresponds to that row number?

i.e. if column B finished in row 6, column c finishes in row 8, column G finishes in row 16, column H finished in row 12 and column I finished in row 10, then the cell to select would be I16, because that's the greatest row number??

If so, try this...

LastB = Range("B65536").End(xlUp).Row
LastC = Range("C65536").End(xlUp).Row
LastG = Range("G65536").End(xlUp).Row
LastH = Range("H65536").End(xlUp).Row
LastI = Range("I65536").End(xlUp).Row


LastOfAll = LastB

If LastC > LastOfAll Then
LastOfAll = LastC
End If
If LastG > LastOfAll Then
LastOfAll = LastG
End If
If LastH > LastOfAll Then
LastOfAll = LastH
End If
If LastI > LastOfAll Then
LastOfAll = LastI
End If

Range("I" & LastOfAll).Select


Am I any nearer now?
 
Upvote 0
Aj,

I had your same idea, but changed it around a bit. Try the following:
Code:
Dim LastRow As Integer
RowArray = Array(2, 3, 7, 8, 9)
For Each i In RowArray
LastRow = Cells(65536, i).End(xlUp).Row
Cells(i - 1, 10) = LastRow
Next i
LastRow = Application.WorksheetFunction.Max(Columns("J"))
ActiveSheet.PageSetup.PrintArea = "$A:$I$" & LastRow
_________________
Hope this helps.
Kind regards, Al.
This message was edited by Al Chara on 2002-04-15 12:06
This message was edited by Al Chara on 2002-04-15 12:21
This message was edited by Al Chara on 2002-04-15 12:25
 
Upvote 0
THANK YOU AJ just what I wanted its a pity I did not explane myself better the first time thanks for staying with me and for EVERYONES help

Stephen
 
Upvote 0
Disregard my previous response, I finally got my head out of my butt. You can also try the following response (should be accurate now):

Dim LastRow, ThisRow As Integer
RowArray = Array(2, 3, 7, 8, 9)
For Each i In RowArray
ThisRow = Cells(65536, i).End(xlUp).Row
If ThisRow > LastRow Then LastRow = ThisRow
Next i
ActiveSheet.PageSetup.PrintArea = "$A$1:$I$" & LastRow
 
Upvote 0
Thanks Cosmos75 for the nice words, but I am no where near the level that some of these guys/girls are at. Learning more everyday, though.
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,685
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top