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

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
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
 
Upvote 0
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.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,213,536
Messages
6,114,215
Members
448,554
Latest member
Gleisner2

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