Next Available Line

L

Legacy 436357

Guest
Hi,

Can this code be edited so it puts the data on the next available line? I sometimes need to delete some data.

Thanks

Code:
Private Sub CommandButton1_Click()
Static xCount As Integer
    Application.EnableEvents = False
    
        Range("J3").Offset(xCount, 0).Value = Range("H6").Value
        Range("K3").Offset(xCount, 0).Value = Range("H3").Value
        Range("L3").Offset(xCount, 0).Value = Format(Now(), "HH:MM:SS")
        xCount = xCount + 1
    
    Application.EnableEvents = True
End Sub
 
What I mean is I will clear data from a row and run again. It posts to the row below the cleared row.

This will result many blank rows which is what I should not have.

Thank you
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Thanks Fluff that works.

What your code is doing is it will paste to the first blank row which could be between rows which is fine.

I appreciate the help guys (or gals).

My next issue is to print my invoice to PDF.
 
Upvote 0
Thanks I have asked too much already. I will figure something out.

hopefully this is what you want.
wasn't trying to be rude, but you should really think about what the person helping you needs to know to complete what you want, or go with their request for example data to work with.
because i certainly do not know if this is exactly what you were looking for.

Code:
Dim ws As Worksheet
Set ws = ActiveSheet

    For Each cell In ws.Columns(10).Cells
        If IsEmpty(cell) = True Then cell.Value = Range("H6").Value: Exit For
    Next cell
    
    For Each cell In ws.Columns(11).Cells
        If IsEmpty(cell) = True Then cell.Value = Range("H3").Value: Exit For
    Next cell
    
    For Each cell In ws.Columns(12).Cells
        If IsEmpty(cell) = True Then cell.Value = Format(Now(), "HH:MM:SS"): Exit For
    Next cell

edit: fluff strikes again. use Fluff's if it works for you.
 
Last edited:
Upvote 0
How about
Code:
Private Sub CommandButton1_Click()
   Dim NxtRw As Long
   Application.EnableEvents = False
   If Range("J3").Value = "" Then
      NxtRw = 3
   Else
      [COLOR=#ff0000]NxtRw = Range("J2").End(xlDown).Offset(1).Row[/COLOR]
   End If
   Range("J" & NxtRw).Value = Range("H6").Value
   Range("K" & NxtRw).Value = Range("H3").Value
   Range("L" & NxtRw).Value = Format(Now(), "HH:MM:SS")

   Application.EnableEvents = True
End Sub

Yeah this is cool,

Guess this has to be "J3" in [NxtRw = Range("J2").End(xlDown).Offset(1).Row]
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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