finding empty cells and entering same data in them using vba from userform

Vans666

New Member
Joined
Jul 29, 2017
Messages
7
[TABLE="align: left"]
<tbody>[TR]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[/TR]
[TR]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[TD]##[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]XXX
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD] ##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[/TR]
[TR]
[TD] ##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[/TR]
[TR]
[TD] ##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]XXX
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
[TR]
[TD] ##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[TD]##
[/TD]
[/TR]
[TR]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[TD]
[/TD]
[/TR]
</tbody>[/TABLE]
I would like to be able to enter the same data into the empty cells marked xxx from a userform using VBA.
The cells marked with a hash are for example only. ie these may be hundreds of rows apart.
Basically how do I use the find function or similar to locate the 2 empty cells marked xxx
All rows filled in above the first xxx
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Assuming we are dealing with cells in column A to E
And we are looking for empty cells in those four columns
And assuming you will enter some value into UserForm Textbox1
And assuming we are dealing with Sheet(1)

Use this script to fill in those cells with the value you entered into Textbox1 on your UserForm.

And to just help you see the results I will highlight the cells in red.
You can remove that part of code later.

Code:
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Dim c As Range
    For Each c In Sheets(1).Range("A1:E" & Cells(Rows.Count, "E").End(xlUp).Row)
        If c.Value = "" Then
            c.Value = TextBox1.Value
            c.Interior.ColorIndex = 3
        End If
    Next
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Thank you very much "my answer is this" for having a go! Unfortunately it is NOT what the doctor ordered .
For clarity in my original post. all hashes refer to filled in cells, the blanks refer to empty cells. I only want the 2 indicated cells filled in with the same data.
Unfortunately your code fills in all blank cells in the indicated columns to the end of the worksheet. all your other assumptions are correct.
Once again thanks for trying. I knew this was going to be a difficult one.
 
Upvote 0
Since MAIT's answer didn't do what you expected, can you clarify the following ..
I would like to be able to enter the same data into the empty cells marked xxx
Are they empty or are they filled with "XXX"?
If empty, how should they be differentiated from all the other empty cells that MAIT's code filled in? For example, is it
- The first empty cell in column D and the first empty cell in column B after the second block of data?
- Something else?
 
Upvote 0
Thank you Peter for making me be more specific !
The first XXX in column D refers to the first empty cell after the block of filled in cells
the blank cells after that can change ie can grow over time
The second XXX in column B is the next empty cell after the next block of filled in cells
 
Upvote 0
Try something like
Code:
Private Sub CommandButton1_Click()
  Columns("D").SpecialCells(xlBlanks).Areas(1).Cells(1).Value = TextBox1.Value
  Columns("B").SpecialCells(xlBlanks).Areas(2).Cells(1).Value = TextBox1.Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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