Finding the next blank row in starting from column "B" returning with values of Textbox1

hitman0801

New Member
Joined
Mar 29, 2018
Messages
3
Hi Team,

I created a userform that would look for the next blank cell starting from Column "B" and return with the value in textbox1. I assigned the sub in commandbutton1 so that whenever I click it, the value of texbox1 will be placed in the next blank cell in column "B". I tried searching in Google and found the codes below:

Code:
irow = ws.Cells(Rows.Count, 8).End(xlUp).Offset(1, 0).Row

.Range("B" & irow) = Textbox1.value

I wanted to start in row 9. However, whenever I run the macro then the value of textbox1 will always be posted in "B9". So in the end, the codes does not look for the next blank cell but only replaces whatever is in cell "B9". I hope you can help me find what's wrong with the codes and suggest corrections. Thanks!
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
The VBA you have identifies the last blank row by going to the bottom of column 8 (aka column H), and comes up until it finds a non blank cell. You can change that to look in column B by changing it to column 2 (aka column B) by modifying it to ws.Cells(Rows.Count, 2)
 
Upvote 0
@gmhumphr- Thank you! Now understand the problem. But what if I want the code to search blanks cells through cells B9:B14 only? As I have a constant value in cell B15 that I don't want to be moved?

[TABLE="class: grid, width: 500, align: center"]
<tbody>[TR]
[TD="align: center"]B9[/TD]
[/TR]
[TR]
[TD="align: center"]B10[/TD]
[/TR]
[TR]
[TD="align: center"]B11[/TD]
[/TR]
[TR]
[TD="align: center"]B12[/TD]
[/TR]
[TR]
[TD="align: center"]B13[/TD]
[/TR]
[TR]
[TD="align: center"]B14[/TD]
[/TR]
[TR]
[TD="align: center"]B15 - Constant Value[/TD]
[/TR]
</tbody>[/TABLE]
 
Upvote 0
Hi Hitman,

The code below replaces the two lines you had above:

Code:
'set up error handling so that if there are no blank cells, it won't give you an error and will continue with the rest of the code
On Error Resume Next

'set the values of the blank cells within the desired range to the value in the textbox
.Range("B9:B14").SpecialCells(xlCellTypeBlanks).Value = Textbox1.Value

'reset error handling to the default error display
on error goto 0
 
Upvote 0
If you only want to put the txtbox value in the first blank in that range try
Code:
On Error Resume Next
.Range("B9:B14").SpecialCells(xlBlanks)(1).Value = TextBox1.Value
On Error GoTo 0
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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