VBA code to copy value from user input to other sheet

hendyhellen

New Member
Joined
Jul 29, 2023
Messages
19
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
Hello all~

Since i found this forum really helpful for learning and troubleshooting VBA code for newbie like me.
I need more help to create small VBA code that able to copy value from Sheet Label -> Cell A4 COPY TO Sheet Data -> Insert row based on every time user scan the barcode

File : Scanning-LABEL

Here is the illustration from what i want it :
This red box based on user input from TextBox1
Screenshot_16.png



After that, i need to copy the value from that part to Sheet Data on Row A2 and below (automatically insert new row)
Screenshot_15.png


Sorry for my bad English :cry:
Thank you all, appreciate for the help(y)
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Will this work.

VBA Code:
Private Sub subTransfarData()
Dim Ws As Worksheet

    Set Ws = Worksheets("Label")
    
    With Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(1, 4)
        .Value = Array(Ws.Cells(4, 1).Value, Ws.Cells(11, 1).Value, Ws.Cells(12, 1).Value, Ws.Cells(13, 1).Value)
    End With
        
End Sub
 
Upvote 1
Solution
Hello Herakles,
I have put the code on new module and nothing happened / maybe i make something wrong when put the code ?

Screenshot_17.png

Will this work.

VBA Code:
Private Sub subTransfarData()
Dim Ws As Worksheet

    Set Ws = Worksheets("Label")
   
    With Worksheets("Data").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Resize(1, 4)
        .Value = Array(Ws.Cells(4, 1).Value, Ws.Cells(11, 1).Value, Ws.Cells(12, 1).Value, Ws.Cells(13, 1).Value)
    End With
       
End Sub
 
Upvote 0
Oh sorry,
Yes the code working

But is there any option to make the code run automatically when workbooks open and copy the value to other sheet in realtime ?

Thank you~
Of course but will the data in 'Labels' not be changed whist you have the workbook open?

Put this code in the Thisworkbook Code Module.

Notice that I have corrected the name of the procedure.

VBA Code:
Private Sub Workbook_Open()

    Call subTransferData

End Sub
 
Upvote 1
Thank you so much Herakles, this code now working 100%

Thread closed now 🙏

Of course but will the data in 'Labels' not be changed whist you have the workbook open?

Put this code in the Thisworkbook Code Module.

Notice that I have corrected the name of the procedure.

VBA Code:
Private Sub Workbook_Open()

    Call subTransferData

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,078
Messages
6,122,996
Members
449,093
Latest member
masterms

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