Excel VBA-Insert application.username into named cells on 2 wkshts if cell is empty.

  • Thread starter Thread starter bstone
  • Start date Start date
B

bstone

I am trying to insert the username into named cells on two worksheets i
the same workbook.

I only want to insert the username if the named cell is blank.

I can insert the names into the correct cells with the following:
(Which is probly very clunky)

With Worksheets("ILTimesheet")
.Range("ILName") = Application.UserName
End With
With Worksheets("AOETimeSheet")
.Range("EmpName") = Application.UserName
End With

But....
I only want to insert the username if the cells ("EmpName" and ILName
are blank.

I think I need to do some sort of IF and IsEmpty but can't seem to ge
it
 
Try something like

If Range("ILName").Value = "" Then
Range("ILName").Value = Application.UserName
End If

Do the same thing for EmpName.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
 
I am trying to insert the username into named cells on two worksheets in
the same workbook.

I only want to insert the username if the named cell is blank.

try this:

Dim rngA As Range
Dim rngB As Range
Set rngA = Worksheets("ILTimesheet").Range("ILName")
Set rngB = Worksheets("AOETimeSheet").Range("EmpName")

If rngA.Value = "" And rngB.Value = "" Then
rngA.Value = Application.UserName
rngB.Value = Application.UserName
End If

--
Regards

Melanie Breden
- Microsoft MVP für Excel -

http://excel.codebooks.de (Das Excel-VBA Codebook)
#Excel-Auftragsprogrammierung#
 
Thank You melanie
I had done the following, and it worked but still clunky.
Your solution is much nicer....

Application.ScreenUpdating = False


Sheets("AOE Time Sheet").Select
' Selects cell A2.
Range("C5").Select
Do While ActiveCell.Value = ""
ActiveCell.Value = Application.UserName

Loop

Sheets("IL TimeSheet").Select
' Selects cell A2.
Range("C5").Select
Do While ActiveCell.Value = ""
ActiveCell.Value = Application.UserName

Loop
Application.ScreenUpdating = True
End Su
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top