• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

find last row number then increment

kamranyd

New Member
Code:
Sub test_1()
  Dim r As Range
  Set r = Range("A" & Range("A" & Rows.Count).End(xlUp).Row)
  r.Offset(1).Value = r.Value + 1
End Sub

i found these codes in your forum. which increase number. i need codes which can check number on sheet2 column A and than show next increment number on sheet1 cell.
for example if sheet2 column have 1 to 10 number, codes check sheet 2 column than show increment in sheet1 any given cell.

it all happen when i open workbook.

thanks
 
Put this code in ThisWorkbook section.
Change A1 to the cell that you want.
Code:
Private Sub Workbook_Open()
Dim r As Range
  Set r = Sheets(2).Range("A" & Range("A" & Rows.Count).End(xlUp).Row)
  Sheets(1).Range("A1").Value = r.Value + 1
End Sub
 
Code:
Sub add()
Dim v As Workbook, cellValue As String

With Worksheets("Sheet2")
    cellValue = .Range("A" & .Cells(.Rows.Count, "A").End(xlUp).Row).Value
End With
    ActiveSheet.Range("A1").Value = Format$((Right$(cellValue, 3) + 1))
End Sub

i m using these codes, there is 1 problem with these codes is that it check last number and increment, can it can also check if any number is missing in between. for example if it is checking number from 1 to 10 and 7 or 4 any number is missing it show that number else it find last number and increment.

thnx for the above codes by the way.
 
Back
Top