copy to the bottom after lastrow instead of replacing with old data

abdo meghari

Active Member
Joined
Aug 3, 2021
Messages
465
Office Version
  1. 2019
Hi guys !
I need modifying this code by copy to the bottom instead of replacing with old data .
the code contains group of textboxes and comboboxes and copy to sheet based on selection option button from column A:H but the problem replacing with old data , should copy to the bottom when every time press commandbutton4
VBA Code:
Private Sub CommandButton4_Click()
Dim i           As Long
    Dim sheetname   As String
  
    For i = 1 To 4
        With Me.Controls("OptionButton" & i)
            If .Value Then sheetname = .Caption: Exit For
        End With
    Next i
  
    With Worksheets(sheetname)
 
  
      .Range("e5").MergeArea = Me.TextBox1.Value
      .Range("e8").MergeArea = Me.TextBox2.Value
  For i = 1 To 11                       'This is unmodified
''        Debug.Print "TextBox_" & i, Cells(i + 1, 1).Address(0, 0)
         .Cells(i + 1, 1).Value = Me.Controls("TextBox" & i)
      Next i

      For i = 12 To 44
''        Debug.Print "TextBox_" & i, Range("F2").Offset((i - 12) Mod 11, Int((i - 12) / 11)).Address(0, 0)
        .Range("F2").Offset((i - 12) Mod 11, Int((i - 12) / 11)).Value = Me.Controls("Textbox" & i)
      Next i
     
      For i = 2 To 45
''        Debug.Print "ComboBox_" & i, Range("B2").Offset((i - 2) Mod 11, Int((i - 2) / 11)).Address(0, 0)
         .Range("B2").Offset((i - 2) Mod 11, Int((i - 2) / 11)).Value = Me.Controls("ComboBox" & i)
      Next i
   End With
  
  TextBox16.Value = Me.TextBox8.Value * Me.TextBox12.Value
 TextBox17.Value = Me.TextBox9.Value * Me.TextBox13.Value
  TextBox18.Value = Me.TextBox10.Value * Me.TextBox14.Value
TextBox34.Value = Me.TextBox12.Value * Me.TextBox23.Value
End Sub
I hope somebody help
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You can find the last row with data in column A like this:
VBA Code:
lr = Cells(Rows.Count, "A").End(xlUp).Row

So then you could dynamically reference the next row to put data in like this:
VBA Code:
Cells(lr + 1, "A").Value = ...
 
Upvote 0

Forum statistics

Threads
1,214,784
Messages
6,121,535
Members
449,037
Latest member
tmmotairi

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