Finding the next available cell in excel sheet - code not working

land144

New Member
Joined
May 25, 2021
Messages
9
Office Version
  1. 2019
i Everyone,

High school teacher from Australia here....trying to make a userform in excel by copying code from the internet, I got this code from here and combined it with another bit of code so it did two things I wanted.

I am trying to copy the contents of a ComboBox1 and TextBox1 into cell B2 and then following on each cell below, all it does is copy the contents into B2 and when I click it again, it copies the new contents into B2 so it looks like the second half of the code isn't working. Total newbie here - I'm just a mathematician so I really don't understand this code as much as literally anyone else here. Any suggestions would be so appreciated.

Private Sub CommandButton2_Click()
Sheets("Comments").Range("B2").Value = ComboBox1.Value & " " & TextBox1.Value
If Range("B2") = Empty Then
Range("B2") = selectedValue
Else
lrow = Cells(Rows.Count, 5).End(xlUp).Row
Cells(lrow + 1, 5) = selectedValue
End If
MsgBox ("Comment is copied")
End Sub
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,252
Office Version
  1. 365
Platform
  1. Windows
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub CommandButton2_Click()
With Sheets("Comments")
   If .Range("B2").Value = "" Then
      .Range("B2") = ComboBox1.Value & " " & TextBox1.Value
   Else
      .Range("B" & Rows.Count).End(xlUp).Offset(1).Value = ComboBox1.Value & " " & TextBox1.Value
   End If
End With
MsgBox ("Comment is copied")
End Sub
 

land144

New Member
Joined
May 25, 2021
Messages
9
Office Version
  1. 2019
T
Hi & welcome to MrExcel.
How about
VBA Code:
Private Sub CommandButton2_Click()
With Sheets("Comments")
   If .Range("B2").Value = "" Then
      .Range("B2") = ComboBox1.Value & " " & TextBox1.Value
   Else
      .Range("B" & Rows.Count).End(xlUp).Offset(1).Value = ComboBox1.Value & " " & TextBox1.Value
   End If
End With
MsgBox ("Comment is copied")
End Sub
hank you so much! That works!! Appreciate the support.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
62,252
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Forum statistics

Threads
1,141,058
Messages
5,704,032
Members
421,323
Latest member
Exidous

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
Top