Specify which row to insert values

ipbr21054

Well-known Member
Joined
Nov 16, 2010
Messages
5,726
Office Version
  1. 2007
Platform
  1. Windows
Morning,

I am using this working code below.

Currently when i run it the values are placed into Row 4
What i would like help / advice with please is as opposed to placing it in row 4 each time let the user specify the row for it to be inserted.

We have a grass cutting round so the customers are on a worksheet in round groups.
So just placing a new customer into row 4 isnt any use sames goes for sorting A-Z etc.

The user will look at the worksheet first & see that this new customer should be inserted into row 11
He would complete the form & then enter in TextBox9 the row number

The code should then create a new row & the values placed in this at row11
The existing value on the worksheet would then all move down 1 row.

Please can you assist.
Have a nice day.



Rich (BB code):
Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim ControlsArr As Variant, ctrl As Variant
    Dim x As Long
    For i = 1 To 6
       With Me.Controls("ComboBox" & i)
            If .ListIndex = -1 Then
                MsgBox "MUST SELECT ALL OPTIONS", 48, "CLONING TRANSFER SHEET"
                .SetFocus
                Exit Sub
            End If
        End With
    Next i
    
    ControlsArr = Array(Me.ComboBox1, Me.ComboBox2, Me.ComboBox3, Me.ComboBox4, Me.ComboBox5, Me.ComboBox6)
    
    With ThisWorkbook.Worksheets("CLONING")
        .Range("A4").EntireRow.Insert Shift:=xlDown
        .Range("A4:F4").Borders.Weight = xlThin
        For i = 0 To UBound(ControlsArr)
         Select Case i
            Case 3
               .Cells(4, i + 1) = Val(ControlsArr(i))
               ControlsArr(i).Text = ""
            Case Else
               .Cells(4, i + 1) = ControlsArr(i)
               ControlsArr(i).Text = ""
         End Select
    Next i
    End With
    
    Application.ScreenUpdating = False

    ActiveWorkbook.Save
    Application.ScreenUpdating = True
    With ThisWorkbook.Worksheets("CLONING")
    .Range("A5").Select
    .Range("A4").Select
    MsgBox "Database Has Been Updated", vbInformation, "SUCCESSFUL MESSAGE"
    End With
End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Just an update as didnt get anywhere with my original request.

Here is my code at present of which send userform value to worksheet & inserts them into row 4

For some reason when i enter a post code example BS25 1AP into TextBox 4 i then transfer the values to the worksheet BUT as opposed to seeing BS25 1AP i actually see 0
I am not sure why BUT i think it has something to do with the code shown below in RED
I am not sure what that part of the code does anyway so now im stuck at present.

Maybe you could advise in basic so i can possibly figure it out.

Thanks

Rich (BB code):
Private Sub CommandButton1_Click()
    Dim i As Integer
    Dim ControlsArr As Variant, ctrl As Variant
    Dim x As Long
    For i = 1 To 11
       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, Me.TextBox11)
    
    With ThisWorkbook.Worksheets("GRASS")
        .Range("A4").EntireRow.Insert Shift:=xlDown
        .Range("A4:K4").Borders.Weight = xlThin
        For i = 0 To UBound(ControlsArr)
         Select Case i
            Case 3
               .Cells(4, i + 1) = Val(ControlsArr(i))
               ControlsArr(i).Text = ""
            Case Else
               .Cells(4, i + 1) = ControlsArr(i)
               ControlsArr(i).Text = ""
         End Select
    Next i
    End With
    
    Application.ScreenUpdating = False

    ActiveWorkbook.Save
    Application.ScreenUpdating = True
    With ThisWorkbook.Worksheets("GRASS")
    .Range("A5").Select
    .Range("A4").Select
    MsgBox "DATABASE HAS NOW BEEN UPDATED", vbInformation, "SUCCESSFUL MESSAGE"
    End With
    Unload GrassNewCustomer
End Sub
 
Upvote 0
This is now what i have but will need to stop as now confused on how to progress.

Upon pressing the command button the Input Box appears.
You enter a number for where the values are to be pasted.

This is where ive now come to & stuck.


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 = Application.InputBox("INSERT DATA TO WHICH ROW ?", "ROW NUMBER MESSAGE BOX", Type:=1)
    For i = 1 To 11
       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, Me.TextBox11)
    
    With ThisWorkbook.Worksheets("GRASS")
        .Range("A4").EntireRow.Insert Shift:=xlDown
        .Range("A4:K4").Borders.Weight = xlThin
        For i = 0 To UBound(ControlsArr)
         Select Case i
            Case 3
               .Cells(4, i + 1) = Val(ControlsArr(i))
               ControlsArr(i).Text = ""
            Case Else
               .Cells(4, i + 1) = ControlsArr(i)
               ControlsArr(i).Text = ""
         End Select
    Next i
    End With
    
    Application.ScreenUpdating = False

    ActiveWorkbook.Save
    Application.ScreenUpdating = True
    With ThisWorkbook.Worksheets("GRASS")
    .Range("A5").Select
    .Range("A4").Select
    MsgBox "DATABASE HAS NOW BEEN UPDATED", vbInformation, "SUCCESSFUL MESSAGE"
    End With
    Unload GrassNewCustomer
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,708
Messages
6,174,006
Members
452,542
Latest member
Bricklin

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