macro question

UPN

Board Regular
Joined
May 14, 2006
Messages
138
Option Explicit

Private Sub CommandButton1_Click()
Dim LastRow As Object
Dim ws As Worksheet
Dim c As Range
Dim FirstAddress As String
Set ws = Sheets("Employees")
Set LastRow = ws.Range("AE65536").End(xlUp)

Unload Me

Application.ScreenUpdating = False
ws.Activate
With ws.Range([AE8], [AE65536].End(xlUp))
Set c = .Find(TextBox1.Value, LookIn:=xlValues)
If Not c Is Nothing Then
FirstAddress = c.Address
Do
MsgBox "Employee number already exists" & vbCrLf & _
"Please try again", vbCritical + vbOKOnly, "User Exists"
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> FirstAddress
UserForm2.Show
End If
End With
Sheets("User Form").Activate
Application.ScreenUpdating = True

With LastRow
' Employee #
.Offset(1, 0) = TextBox1.Value
' Employee Name
.Offset(1, 1) = TextBox2.Value
' Start Date
.Offset(1, 2) = TextBox3.Value
End With

' Add Exempt Status
If OptionButton1 = True Then LastRow.Offset(1, 3) = "Exempt"
If OptionButton2 = True Then LastRow.Offset(1, 3) = "NonExempt"
If OptionButton3 = True Then LastRow.Offset(1, 3) = "PartTime"

End Sub

i have this macro that makes a table of employees. to put the person name like this Joe SMoe

can i use the formula listed below in macro to change it to Smoe, Joe

=RIGHT(AF9,LEN(AF9)-FIND(" ",AF9))&", "&LEFT(AF9,FIND(" ",AF9)-1)
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".

erik.van.geit

MrExcel MVP
Joined
Feb 1, 2003
Messages
17,832
Hi,

Barry Houdini learned me a shorter formula yesterday:
=MID(A1&" "&A1,FIND(" ",A1)+1,LEN(A1))

implemented in your code
Code:
.Offset(1, 1) = Mid(TextBox2 & " " & TextBox2, InStr(1, TextBox2, " ") + 1, Len(TextBox2))

kind regards,
Erik
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,834
Messages
5,855,897
Members
431,772
Latest member
dannyboi1

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
Top