1
votes

I have two sheets. I already have a button to save the data to another sheet called "Data" and it is well working. Now I created one button which needs to do two jobs. It will clear cells (shown in the code) and then it will put in the cell C2 next consecutive number.

Sub ClearButton()
Range("L1", "L2").Clear
Range("C2", "B3").Clear
Range("J5", "K5").Clear
End Sub

I want the cell C2 in this Entry sheet to check the column A in another sheet called "Data". In the Data sheet in column A it saves all the customer number as 1,2,3 and carries on. So it must check the last entry or the maximum number in the column A rows. So if the maximum number in Column A(Data Sheet) is 5 then it will put in cell C2(Entry Sheet) 6 so that new entry is done.

1
Are you working in Visual Studio? Is the VBA?Mary
Nope. Just in Excel.Waqar

1 Answers

2
votes

Something like this? This will grab the last value in column A on the sheet Data, add 1 to it, and set C2 on the ActiveSheet to the value.

Note that if the data in column A on the Data sheet is not a number, this may throw an error and need to be handled.

Sub ClearButton()
Range("L1", "L2").Clear
Range("C2", "B3").Clear
Range("C2").Value = Sheets("Data").Range("A" & Rows.CountLarge).End(xlUp).Row + 1
Range("J5", "K5").Clear
End Sub