How to edit my code so that it can copy multiple data to another worksheet

jovie

Board Regular
Joined
Nov 13, 2015
Messages
68
Hi, I write a code to copy data from one worksheet to another, however my code is only able to copy one row, but I need it to copy multiple row
Private Sub CommandButton1_Click()
Set MLSA = Sheets("MasterList-Sawing")

Set SS = Sheets("Sawing Schedule")

malr = MLSA.Range("a65535").End(xlUp).Row

sslr = SS.Range("a65535").End(xlUp).Row

a = 0

For i = 2 To malr

If MLSA.Cells(i, "B") & "" = TextBox1 Then

a = i

Exit For

End If

Next




If a = 0 Then
MsgBox "Sorry, No exiting Part Number", vbOKOnly, "Not Found"
Unload UserForm1

Exit Sub

End If


Set rg = MLSA.Range("A" & a)

rg.Copy SS.Range("D" & (sslr + 1))

Set rg = MLSA.Range("C" & a & ":E" & a)

rg.Copy SS.Range("F" & (sslr + 1))

Set rg = MLSA.Range("F" & a)
rg.Copy SS.Range("J" & (sslr + 1))

Set rg = MLSA.Range("G" & a)
rg.Copy SS.Range("M" & (sslr + 1))


Set rg = MLSA.Range("H" & a)
rg.Copy SS.Range("O" & (sslr + 1))

SS.Cells(sslr + 1, "E") = TextBox1

SS.Cells(sslr + 1, "A") = TextBox2

SS.Cells(sslr + 1, "B") = TextBox3

SS.Cells(sslr + 1, "C") = TextBox4

Unload Me

End Sub

Private Sub CommandButton2_Click()
Unload Me
End Sub
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Are you sure you wrote this script. Or is it bits and pieces you have found?
I see "Unload UserForm1"
But I never see UserForm1 show

Maybe you can just tell us what your wanting to do.
 
Upvote 0
Are you sure you wrote this script. Or is it bits and pieces you have found?
I see "Unload UserForm1"
But I never see UserForm1 show

Maybe you can just tell us what your wanting to do.

..... This code is write for the userform, the button 1 is to place the data that I have search, the button 2 is used to unload the userform while not entering anything. As for the userform1 show, it is in another button so when I click the button, the userform will show.
So, I was try to copy data that share with same part number, which for the worksheet MasterList_Sawing is column B, and for the worksheet Sawing Schedule is column E
But I only can copy data for the same part number in MasterList_Sawing's first row that meet the requirement, which is the textbox1 is equal to column E in MasterList_Sawing.
But I want to copy multiple row.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,326
Members
452,635
Latest member
laura12345

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