Move existing row of value to another selected row

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,226
Office Version
  1. 2007
Platform
  1. Windows
Morning,
I am currently adding values to a userform then i see a input box asking me which row i would like the row of values to be added in the worksheet,this to me is a good so maybe to save you time ive supplied the code below that does this.

So my goal today is to be able to move a row of value from its current row position to another row position.

Example.
Mrs Smith is currently on Row 10 but i wish to move her values to Row 4
So the code will need to copy values from her Row 10, insert a new row at Row 4 & then add the values.

My Row range is A to K

Thanks



Rich (BB code):
Private Sub CommandButton1_Click()
 Dim i As Integer
 Dim ControlsArr As Variant, ctrl As Variant
 Dim x As Long
 Dim z As Integer
 
 z = CInt(Application.InputBox("WHICH ROW SHOULD DATA BE INSERTED INTO ?", "NEW CUSTOMER ROW NUMBER MESSAGE", Type:=1))
 For i = 1 To 10
 With Me.Controls("TextBox" & i)
 If .Text = "" Then
 MsgBox "ALL FIELDS MUST BE COMPLETED", 48, "GRASS NEW CUSTOMER FORM"
 .SetFocus
 Exit Sub
 End If
 End With
 Next i
 
 
 ControlsArr = Array(Me.TextBox1, Me.TextBox2, Me.TextBox3, Me.TextBox4, Me.TextBox5, Me.TextBox6, Me.TextBox7, Me.TextBox8, Me.TextBox9, Me.TextBox10)
    With ThisWorkbook.Worksheets("GRASS")
    .Rows(z).EntireRow.Insert Shift:=xlDown
    .Rows(z).RowHeight = 25
    Range(.Cells(z, "A"), .Cells(z, "K")).Borders.LineStyle = xlContinuous
    For i = 0 To UBound(ControlsArr)
    Select Case i
    Case -1
    .Cells(z, i + 1) = Val(ControlsArr(i))
    ControlsArr(i).Text = ""

    Case Else
    .Cells(z, i + 1) = ControlsArr(i)
    ControlsArr(i).Text = ""
    End Select
    Next i
    End With

 ActiveWorkbook.Save
    
 Unload GRASSNEWCUSTOMER
 MsgBox "DATABASE HAS NOW BEEN UPDATED", vbInformation, "SUCCESSFUL MESSAGE"
 
End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
So far after a while ive managed this below.

The user can select the customers name in column A
The user then selects the Command Button & the values from column A to L are copied.
The input box pops up where the user then enters the row he wishes the values to be pasted to.

At present im now stuck on how to continue.
If the user enters 15 the input box should close, A new row should be inserted & the value pasted thus being row 15.


SQL:
Private Sub MoveValue_Click()
  Dim UserInput As String
     ActiveCell.Resize(1, 12).Copy
     UserInput = VBA.Interaction.InputBox("PLEASE ENTER ROW NUMBER", "MOVE TO ROW MESSAGE")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,953
Members
449,095
Latest member
nmaske

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