Copying a range and pasting it several times from a user form

TitoElan

New Member
Joined
Jun 10, 2022
Messages
24
Office Version
  1. 365
Platform
  1. Windows
Hi,

I want to copy a range and paste it several times via a user form using a text box. It already works fine but I can only copy and paste that range once. I want to paste it as many times as the user wants with the textbox input.

Thats my code at the moment.
I would apreciate some help. Thanks!
VBA Code:
Private Sub CommandButton1_Click()
Dim entradas As Integer
TextBox1.Value = entradas

    If TextBox1.Value > 0 Then
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Title = Application.ActiveWorkbook.Name
        Worksheets("Bausteine").Activate
        Range("A3:Q3").Select
        Selection.Copy
        Worksheets("F-Kalk").Activate
        Selection.Insert Shift:=xlDown
        Application.CutCopyMode = False
        FindReplace
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
        Exit Sub
    Else
        Exit Sub
    End If
End Sub

Edit: it is working with 1x paste but if I delete those 2 lines
Dim entradas As Integer
TextBox1.Value = entradas
There are in the code cause I was trying to find a solution :D
 
Last edited by a moderator:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
It seems that I already found the solution :D

VBA Code:
Private Sub CommandButton1_Click()
Dim nbr As Long
    nbr = TextBox1.Value
    If nbr > 0 Then
        Application.ScreenUpdating = True
        Application.DisplayAlerts = False
        Title = Application.ActiveWorkbook.Name
        Worksheets("Bausteine").Activate
        Range("A3:Q3").Select
        Selection.Copy
        Worksheets("F-Kalk").Activate
        
        For i = 1 To nbr
            Selection(i).Resize(nbr).Insert Shift:=xlDown

            FindReplace
        Next
        
        Application.DisplayAlerts = True
        Application.ScreenUpdating = True
        lv_eingabe.Hide
    Else
        MsgBox "Wert falsch oder kleiner als 1"
    
    End If
    
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,223,879
Messages
6,175,147
Members
452,615
Latest member
bogeys2birdies

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