ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   find last item in record (https://www.excelbanter.com/excel-programming/378603-find-last-item-record.html)

Ernie

find last item in record
 
i use the code below to find the last record in my workbook. some times it
work without problem some times it goes to the last record even if the first
record is empty. can someone help me with this code. how can i simplify it?

Private Sub MultiPage1_Change()
If MultiPage1.Pages(3).Visible = True Then

'check for last item
Workbooks("Declaration Pro.xls").Worksheets("Classification").Activate
Range("B5").Select
If ActiveCell.Value < "" Then
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(-1, 0).Select
End If
'load controls with last item's value------------
cboTariffNo.Value = ActiveCell.Value
txtDescription.Value = ActiveCell.Offset(0, 1).Value
txtItemFob.Value = ActiveCell.Offset(0, 4).Value
cboCPC.Value = ActiveCell.Offset(0, 18).Value
txtSupplQuantity.Value = ActiveCell.Offset(0, 19).Value
cboCountryOfOrigin.Value = ActiveCell.Offset(0, 20).Value
txtNoPackage.Value = ActiveCell.Offset(0, 21).Value
cboPackageType.Value = ActiveCell.Offset(0, 22).Value
cboEnvSurChar.Value = ActiveCell.Offset(0, 25).Value
txtNetWeight.Value = ActiveCell.Offset(0, 26).Value
lblItemNo.Caption = ActiveCell.Offset(0, -1)
End If
End Sub

Don Guillett

find last item in record
 
something like

lc=cells(rows.count,"b").end(xlup).row
cboTariffNo.value=Cells(lc, 2).Offset(0,0)
txtDescription.Value = cells(lc,2).Offset(0, 1)
etc



--
Don Guillett
SalesAid Software

"ernie" wrote in message
...
i use the code below to find the last record in my workbook. some times it
work without problem some times it goes to the last record even if the
first
record is empty. can someone help me with this code. how can i simplify
it?

Private Sub MultiPage1_Change()
If MultiPage1.Pages(3).Visible = True Then

'check for last item
Workbooks("Declaration Pro.xls").Worksheets("Classification").Activate
Range("B5").Select
If ActiveCell.Value < "" Then
Do
If IsEmpty(ActiveCell) = False Then
ActiveCell.Offset(1, 0).Select
End If
Loop Until IsEmpty(ActiveCell) = True
ActiveCell.Offset(-1, 0).Select
End If
'load controls with last item's value------------
cboTariffNo.Value = ActiveCell.Value
txtDescription.Value = ActiveCell.Offset(0, 1).Value
txtItemFob.Value = ActiveCell.Offset(0, 4).Value
cboCPC.Value = ActiveCell.Offset(0, 18).Value
txtSupplQuantity.Value = ActiveCell.Offset(0, 19).Value
cboCountryOfOrigin.Value = ActiveCell.Offset(0, 20).Value
txtNoPackage.Value = ActiveCell.Offset(0, 21).Value
cboPackageType.Value = ActiveCell.Offset(0, 22).Value
cboEnvSurChar.Value = ActiveCell.Offset(0, 25).Value
txtNetWeight.Value = ActiveCell.Offset(0, 26).Value
lblItemNo.Caption = ActiveCell.Offset(0, -1)
End If
End Sub





All times are GMT +1. The time now is 11:57 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com