initials?

Smoakstack

Board Regular
Joined
Mar 28, 2011
Messages
79
here is my code

Public Sub Workbook_Open()
Dim nam As String

If Sheet2.Range("Z1") = "" Then

'Input of name
nam = InputBox("Enter your name.", "Summary", "Name")

'Unlock Information
Sheet1.Unprotect Password:=""
Sheet2.Unprotect Password:=""
Sheet3.Unprotect Password:=""
Sheet4.Unprotect Password:=""
Sheet5.Unprotect Password:=""
Sheet6.Unprotect Password:=""
Sheet7.Unprotect Password:=""
Sheet8.Unprotect Password:=""
Sheet9.Unprotect Password:=""
Sheet10.Unprotect Password:=""

If nam = "" Then
Sheets("SUMMARY").Range("A3").Value = "Name"
Else
Sheets("SUMMARY").Range("A3").Value = nam
End If
End if

'Other code below

End Sub

I would like Range A3 to be the initials of the variable nam?

Is there a way to do this?
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Try:

Code:
Public Sub Workbook_Open()
Dim nam As String, _
    i   As Long
If Sheet2.Range("Z1") = "" Then
    'Input of name
    nam = InputBox("Enter your name.", "Summary", "Name")
    
    'Unlock Information
    For i = 1 To 10
        Sheets(i).Unprotect Password:=""
    Next i
    
    If InStr(nam, " ") <> 0 And Len(nam) > 0 Then
        Sheets("SUMMARY").Range("A3").Value = UCase$(Left$(nam, 1)) & UCase$(Mid(nam, InStr(nam, " ") + 1, 1))
    ElseIf Len(nam) > 0 Then
        Sheets("SUMMARY").Range("A3").Value = nam
    Else
        Sheets("SUMMARY").Range("A3").Value = "Name"
    End If
End If
End Sub
 
Upvote 0
bump

Anyone have any ideas?

here is the code.

If nam = "" Then
Sheets("SUMMARY").Range("A3").Value = "Estimator"
Else
Sheets("SUMMARY").Range("A3").Value = UCase$(Left$(nam, 1)) & UCase$(Mid(nam, InStr(nam, " ") + 1, 1))
End If

Subscript out of range happens on both cases
 
Upvote 0
Do you have a worksheet named "Summary"?
 
Upvote 0
It isn't case sensitive.

Try running the following macro to see if it errors:

Code:
Public Sub foo()
Sheets("Summary").Range("A3").Value = 1
End Sub
 
Upvote 0
Can you please copy over the entire code you are using? I had placed the if instr(nam, " ") <> 0 and len(nam)>0 line in there so that the code would not error if someone entered only their first or last name (ie there would be no space).
 
Upvote 0
got it to work. Had to erase your password For lines and replace back to existing (?)

Public Sub Workbook_Open()
Dim nam As String
Dim bid As String
Dim Job As String
Dim loc As String
Dim Reply As String
Dim i As Long
Dim InStr As String

If Sheet2.Range("Z1") = "" Then
'Input of Estimators' Name
nam = InputBox("Enter your name.", "Summary", "Estimator")
'Unlock Information
Sheet1.Unprotect Password:=""
Sheet2.Unprotect Password:=""
Sheet3.Unprotect Password:=""
Sheet4.Unprotect Password:=""
Sheet5.Unprotect Password:=""
Sheet6.Unprotect Password:=""
Sheet7.Unprotect Password:=""
Sheet8.Unprotect Password:=""
Sheet9.Unprotect Password:=""
Sheet10.Unprotect Password:=""
OSTExport20.Unprotect Password:=""


If InStr(nam, " ") <> 0 And Len(nam) > 0 Then
Sheets("SUMMARY").Range("A3").Value = UCase$(Left$(nam, 1)) & UCase$(Mid(nam, InStr(nam, " ") + 1, 1))
ElseIf Len(nam) > 0 Then
Sheets("SUMMARY").Range("A3").Value = nam
Else
Sheets("SUMMARY").Range("A3").Value = "Name"
End If

'Other Code here

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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