Getting inputbox to ignore non-blank cells

Milos

Board Regular
Joined
Aug 28, 2016
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have developed a macro that auto-fills selected cells based on an inputbox. I am in need of assistance to finish it off.

Code:
Sub Initials()
 Dim r As Range
 Dim c As Range
 Dim name As Variant
 Set r = Application.InputBox("Select cell(s)", "Demo", , , , , , 8)
 r.Select
 name = InputBox("Enter workers Initials:")
 For Each c In r.Cells
    r.Cells = name
 Next c
 End Sub

What I need is an update to this code so that if a selected cell is non-blank then it will ignore the cell and move on to the next selected cell. I am not sure how to add this in. Currently the inputbox will over-right any non-blank cells with the entered initials. Can somebody please help me add this code in to this macro?

Thanks team!
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
how's this?
Code:
Sub Initials()
 Dim r As Range
 Dim c As Range
 Dim name As Variant
 Set r = Application.InputBox("Select cell(s)", "Demo", , , , , , 8)
 r.Select
 name = InputBox("Enter workers Initials:")
 For Each c In r.Cells
    If IsEmpty(c) Then
    c = name
    Else
    End If
 Next c
 End Sub

IsEmpty() checks if the cell is empty
also i think the r.Cells = name in your For Each loop changes the value of all the cells in your range to the input initials instead of just the cell the loop is checking for so i changed it to just c = name
 
Upvote 0

Forum statistics

Threads
1,215,350
Messages
6,124,431
Members
449,158
Latest member
burk0007

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