recording data at the last blank cell

coolman

New Member
Joined
Nov 21, 2017
Messages
36
hi

I have a syntax here to record data however it keep recording over the previous data. Could anyone advice me how to program that all new data is to be recorded at new row of blank cells without over write the previous entry?

Dim ws As Worksheet
Set ws = Worksheets("budget tracking")
Dim newrow As Long


If Me.CBBudgetCode.ListIndex <> -1 And Len(Me.TxtBoxPurchaseDate.Value) = 10 And Me.TxtBoxPORefNo.Value <> "" And Me.TxtBoxVendorName.Value <> "" And Me.TxtBoxQuantity.Value <> "" And Me.CBUnit.ListIndex <> -1 And Me.TxtBoxRate.Value <> "" And Me.CBLocation.ListIndex <> -1 And Me.TxtBoxTransctionDetails.Value <> "" Then


newrow = Application.WorksheetFunction.CountA(ws.Range("b:b")) + 6


ws.Cells(newrow, 2).Value = Me.CBBudgetCode.Value
ws.Cells(newrow, 3).Value = Me.TxtBoxPurchaseDate.Value
ws.Cells(newrow, 4).Value = Me.TxtBoxPORefNo.Value
ws.Cells(newrow, 5).Value = Me.TxtBoxVendorName.Value
ws.Cells(newrow, 6).Value = Me.TxtBoxItemPurchased.Value
ws.Cells(newrow, 7).Value = Me.TxtBoxQuantity.Value
ws.Cells(newrow, 8).Value = Me.CBUnit.Value
ws.Cells(newrow, 9).Value = Me.TxtBoxRate.Value
ws.Cells(newrow, 10).Value = Me.TxtAmount.Value
ws.Cells(newrow, 11).Value = Me.CBLocation.Value
ws.Cells(newrow, 12).Value = Me.TxtBoxTransctionDetails.Value
End If
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Could you not add an IF statement for each cell to see if the cell is empty?

For example ...

Code:
If Trim(ws.Cells(newrow, 2).value = "" Then
    ws.Cells(newrow, 2).Value = Me.CBBudgetCode.Value
End If

Do that for each of the cells you wish to check before updating. There may be more elegant solutions but that's the one I thought of in the shortest possible time.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

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