So I am trying to create a button that opens a userform thatasks questions on what the user wants to do. It is kind of hard to explain so Iam going to try to insert screen shots of what I want to happen.
Below is part of a table that is created on the main pageentitled “Status Sheet.”
[TABLE="width: 297"]
<tbody>[TR]
[TD="width: 44"]
[/TD]
[TD="width: 139"]miller
[/TD]
[TD="width: 53"]
[/TD]
[TD="width: 33"]
[/TD]
[TD="width: 36"]2
[/TD]
[TD="width: 45"]
[/TD]
[TD="width: 45"]
[/TD]
[/TR]
[TR]
[TD="width: 44"]
[/TD]
[TD="width: 139"]Hardy
[/TD]
[TD="width: 53"]
[/TD]
[TD="width: 33"]
[/TD]
[TD="width: 36"]1
[/TD]
[TD="width: 45"]
[/TD]
[TD="width: 45"]
[/TD]
[/TR]
</tbody>[/TABLE]
I want to be able to move “miller” and replace “hardy” thenbe asked where “hardy” should then be placed when “miller” is placed into “hardys”room number.
First userform that appears
**one box with title above that asks which person will bemoving**
I want to put “miller” into “hardy” room, and then be askedwhere to put “hardy.”
Second screen shot
**Left side box, has persons name that was entered previous.On the right hand side has a box to enter which number to move said person to**
Asking me which room I want to put “miller” into.
I enter the room, 217, which is currently housed to “hardy.”The macro enters “miller’s” information into hardys room, then copies hardysinformation and asks where to put his.
**Same as above, but has persons name who was in theprevious room, on right were to put said person****
When I then enter a room number for hardy’s it pastes it.
The first time around, everything works perfect, but thesecond time around it doesn’t.
***What happens?***
When I enter the name of the person the second time tryingto work the button, on the second screen, the name of the person who I entereddoes not show up. I enter in the room number in the area, then it just ends. IfI close excel and reopen it, it runs perfect the first time, but does the sameagain. Below is my code for each userform.
Userform2 (first screen that pops up)
Userform1, which is second screen
The final userform3
I really hope this makes sense. Please help.
Below is part of a table that is created on the main pageentitled “Status Sheet.”
[TABLE="width: 297"]
<tbody>[TR]
[TD="width: 44"]
216
[TD="width: 139"]miller
[/TD]
[TD="width: 53"]
2
[TD="width: 33"]
2
[TD="width: 36"]2
[/TD]
[TD="width: 45"]
2
[TD="width: 45"]
2
[/TR]
[TR]
[TD="width: 44"]
217
[TD="width: 139"]Hardy
[/TD]
[TD="width: 53"]
1
[TD="width: 33"]
1
[TD="width: 36"]1
[/TD]
[TD="width: 45"]
1
[TD="width: 45"]
1
[/TR]
</tbody>[/TABLE]
I want to be able to move “miller” and replace “hardy” thenbe asked where “hardy” should then be placed when “miller” is placed into “hardys”room number.
First userform that appears
**one box with title above that asks which person will bemoving**
I want to put “miller” into “hardy” room, and then be askedwhere to put “hardy.”
Second screen shot
**Left side box, has persons name that was entered previous.On the right hand side has a box to enter which number to move said person to**
Asking me which room I want to put “miller” into.
I enter the room, 217, which is currently housed to “hardy.”The macro enters “miller’s” information into hardys room, then copies hardysinformation and asks where to put his.
**Same as above, but has persons name who was in theprevious room, on right were to put said person****
When I then enter a room number for hardy’s it pastes it.
The first time around, everything works perfect, but thesecond time around it doesn’t.
***What happens?***
When I enter the name of the person the second time tryingto work the button, on the second screen, the name of the person who I entereddoes not show up. I enter in the room number in the area, then it just ends. IfI close excel and reopen it, it runs perfect the first time, but does the sameagain. Below is my code for each userform.
Userform2 (first screen that pops up)
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub CommandButton1_Click()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]If (Me.TextBox1.Value) = "" Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]MsgBox "is empty"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Else: MsgBox "copy"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(What:=Me.TextBox1.Value, After:=ActiveCell, LookIn:=xlValues,LookAt:= _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]xlWhole,SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000],SearchFormat:=False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell,ActiveCell.Offset(0, 6)).Copy[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Select[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range("A1:F1").Insert[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(What:=Me.TextBox1.Value, After:=ActiveCell,LookIn:=xlValues, LookAt:= _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]xlWhole,SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000],SearchFormat:=False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell,ActiveCell.Offset(0, 6)).ClearContents[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]UserForm1.Show[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox1.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
Userform1, which is second screen
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub UserForm_Initialize()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]UserForm1.TextBox2.Value = CStr(UserForm2.TextBox1.Value)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub CommandButton1_Click()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]If (Me.TextBox2.Value) = "" Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]MsgBox "isempty"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Else: MsgBox "run"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("StatusSheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(What:=Me.TextBox3.Value, After:=ActiveCell,LookIn:=xlValues, LookAt:= _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]xlWhole,SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000],SearchFormat:=False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]IfActiveCell.Offset(0, 1).Value = "" Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]MsgBox"will paste"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(Me.TextBox2.Value, ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell, ActiveCell.Offset(0, 5)).Copy[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(Me.TextBox3.Value, ActiveCell, xlValues, xlWhole, xlByRows,xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.Offset(0, 1).PasteSpecial[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(Me.TextBox2.Value,ActiveCell, xlValues, xlWhole, xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.EntireRow.Delete[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox2.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox3.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Else: MsgBox"space full"[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 6)).Copy[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Select[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range("A1:F1").Insert[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(What:=Me.TextBox3.Value, After:=ActiveCell,LookIn:=xlValues, LookAt:= _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext,MatchCase:=False _[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000],SearchFormat:=False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 6)).ClearContents[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(Me.TextBox2.Value, ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell, ActiveCell.Offset(0, 5)).Copy[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(Me.TextBox3.Value, ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.Offset(0, 1).PasteSpecial[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveSheet.Cells.find(Me.TextBox2.Value, ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.EntireRow.Delete[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]UserForm3.Show[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox2.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox3.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
The final userform3
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub UserForm_Initialize()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]UserForm3.TextBox1.Value =CStr(ThisWorkbook.Sheets("Sheet1").Range("A1").Value)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub CommandButton1_Click()[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(Range("A1"), ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Range(ActiveCell, ActiveCell.Offset(0, 5)).Copy[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(Me.TextBox2.Value, ActiveCell, xlValues, xlWhole, xlByRows,xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.Offset(0,1).PasteSpecial[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Sheet1").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Cells.find(Range("A1"), ActiveCell, xlValues, xlWhole,xlByRows, xlNext, False, False).Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]ActiveCell.EntireRow.Delete[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Sheets("Status Sheet").Activate[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox1.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.TextBox2.Value = ""[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Me.Hide[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
I really hope this makes sense. Please help.