PDA

View Full Version : Copy and Enter Current Record Displayed in Userform a # of Times to WS



Loss1003
02-10-2016, 01:43 PM
Currently using the below code to delete the current record displaying in my user-form. However, i want to add a command button with code that will allow me to copy and insert current record displaying a # of times. The number will of course change depending on what the user requires. Perhaps someone can help me edit to achieve:).


Private Sub Delete1_Click()

Dim lReply As Long
lReply = MsgBox("Are you sure you wish to delete this account?", vbYesNoCancel + vbQuestion)

If lReply = vbNo Then
Exit Sub
ElseIf lReply = vbYes Then

Dim strFind
Dim Nullstring
Dim rSearch As Range 'range to search
Set rSearch = Sheet2.Range("B1:B50000")
Dim c
Dim r As Long


strFind = UserForm1.LCfile.Value
If strFind = Nullstring Then GoTo error1

With rSearch
Set c = .Find(strFind, LookIn:=xlValues, MatchCase:=True)
If Not c Is Nothing Then 'found it

c.EntireRow.Select
c.EntireRow.Delete
combranch.Value = ""

With Sheet2
Dim rng As Range, c_rng As Range, rng_num As Double
Set rng = Range("B2", Range("B2").End(xlDown))
rng_num = 1
For Each c_rng In rng
With c_rng
.Value = rng_num
rng_num = rng_num + 1
End With
Next
End With

'rownumber.Text = FindLastRow
RowNumber.Text = RowNumber.Text - 1
End If
End With

With Me

' ClearData
End With

MsgBox "Record Sucessfully deleted", vbOKOnly

Else
End If

error1: Exit Sub
UserForm_Initialize

End Sub