VBA Code to stack values even if no value is in above row

Malcolm torishi

Board Regular
Joined
Apr 26, 2013
Messages
219
Hi
can anyone tell me if there is a VBA Code to do this. I have a VBA Code that insert values onto rows on my spreadsheet each time I press a command button on my userform and each time I press command button it put that values underneath one another. But sometimes if one of my text boxes does not have any value in it the next time I press the command button the value that should say go onto to 10 does jump up to row 9 if there is no value in the row above.
So my question is , is there a VBA Code to stop this and keep the value stacking underneath each other if there is no value above.
Thank you
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I think we might need more detail of exactly what you have and what you are trying to achieve.
 
Upvote 0
If we are dealing with entering value in column A first empty cell
Try this:
Code:
Sub Check_Up()
'Modified  7/28/2019  5:43:42 AM  EDT
Dim FirstEmpty As Long
FirstEmpty = Range("A1").End(xlDown).Row + 1
Cells(FirstEmpty, 1).Value = "Alpha"

End Sub
 
Upvote 0
Code:
Sub appendToSheet(ByVal appendValue As String, Optional targetSht As Worksheet, Optional targetColumn As String = "A")
    If targetSht Is Nothing Then Set targetSht = ActiveSheet
    With targetSht.Cells(targetSht.Rows.Count, targetColumn).End(xlUp)
        If .Value = "" Then
            .Value = appendValue
        Else
            .Offset(1).Value = appendValue
        End If
    End With
End Sub

you can call that sub from within your existing code like so:

Code:
    appendToSheet "new value" '<--Appends to active sheet in column A
    appendToSheet "newer value", Sheets("Sheet1") '<--Appends to a named sheet in column A
    appendToSheet "newest value", Sheets("Sheet1"), "B" '<--Appends to a named sheet in column B
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,263
Members
452,627
Latest member
KitkatToby

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