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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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
 
Upvote 0

Forum statistics

Threads
1,214,590
Messages
6,120,421
Members
448,961
Latest member
nzskater

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