About adding 3 lines of information

muhittinemmi

New Member
Joined
Jun 20, 2023
Messages
19
VBA Code:
Private Sub CommandButton8_Click()
Dim emmi As Long, Say As Byte
emmi = Range(Range("I2").Value).End(3).Row + 1
If Cells(emmi, "a").Value <> "" Then
MsgBox "There must be at least 3 lines of space ", vbInformation, "Teklif"
Exit Sub
End If
Cells(emmi, "A").Value = "Satır 1"
Cells(emmi + 1, "A").Value = "Satır 5"
Cells(emmi + 2, "A").Value = "Satır 3"
End Sub

When I click the button, I add 3 lines of information
When I click the button, if all lines are filled, I get a warning that there must be at least 3 lines of space before I can add.

The "I2" content shows the last line.

Example: If 2 lines are empty, when I click the button, 2 lines of information are added " Cells(emmi, "A").Value = "Line 1"
and Cells(emmi + 1, "A").Value = "Line 5" " 3rd line is missing

If 1 or 2 lines of space are left when the button is clicked, how can I give the warning "There must be at least 3 lines of space" without adding anything?
 
Last edited:

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Maybe...
VBA Code:
Private Sub CommandButton8_Click()
    Dim emmi As Long
   
    emmi = Range(Range("I2").Value).End(3).Row + 1
 
    If Application.CountA(Cells(emmi, "a").Resize(3)) <> 0 Then
        MsgBox "There must be at least 3 lines of space ", vbInformation, "Teklif"
        Exit Sub
    End If
   
    Cells(emmi, "A").Resize(3).Value = Application.Transpose(Array("Satir 1", "Satir 5", "Satir 3"))
End Sub
 
Last edited:
Upvote 0
Hello
The code does not work because the last line is empty, the data is appended to the lines after the last line.
The codes work when any value is added to the last line.
Solved my problem thanks.
 
Upvote 0
The code does not work because the last line is empty, the data is appended to the lines after the last line.
I assumed that you had how your last row and (therefore where the data was placed) sorted because you did not state that you had an issue with this, you only stated that you had an issue with how to tell that the 3 cells were empty.
The code posted uses emmi = Range(Range("I2").Value).End(3).Row + 1 as it's start point, which I assumed that the +1 you had was giving you the line after your last row (which it does as the next row is empty), and that was the row that you wanted.
As I said you did not state that this was giving you the wrong start cell and so I didn't look at it (the start cell is exactly the same as you had in your original code).

Happy that you have got it sorted
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,045
Messages
6,128,480
Members
449,455
Latest member
jesski

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