473,587 Members | 2,487 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How To Copy a Row of information to individual cells on another sheet

1 New Member
I am trying to copy a row of information from one sheet to different selected cells on another sheet using a command button that allows you to specify which row you want to copy from and paste that information onto another sheet in specific cells. This is what I have so far, as you can see I have tried several different methods however nothing is working so far.

Private Sub CancelButton_Cl ick()

Unload Me

End Sub
------------------------------------------
Private Sub ClearButton_Cli ck()

Call UserForm_Initia lize

End Sub
---------------------------------------------
Private Sub OKButton_Click( )

'Determine Row
RowNumber = Me.TextBox1.Val ue

'copy the data

Sheets("Sheet1" ).Range("RowNum ber,1").Copy
Sheets("Sheet2" ).Range("B,1"). Paste
'Sheets("Sheet1 ").Range("RowNu mber,2").Copy
'Sheets("Sheet2 ").Range("B,2") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,3").Copy
'Sheets("Sheet2 ").Range("B,3") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,4").Copy
'Sheets("Sheet2 ").Range("C,3") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,5").Copy
'Sheets("Sheet2 ").Range("B,4") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,6").Copy
'Sheets("Sheet2 ").Range("B,5") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,7").Copy
'Sheets("Sheet2 ").Range("B,7") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,8").Copy
'Sheets("Sheet2 ").Range("C,9") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,9").Copy
'Sheets("Sheet2 ").Range("D,7") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,10").Copy
'Sheets("Sheet2 ").Range("C,7") .Paste
'Sheets("Sheet1 ").Range("RowNu mber,11").Copy
'Sheets("Sheet2 ").Range("D,12" ).Paste


'ThisWorkbook.S heets("Sheet1") .Cells("RowNumb er,1") = ThisWorkbook.Sh eets("Sheet2"). Cells("B,1")
'ThisWorkbook.S heets("Sheet1") .Cells("RowNumb er,2") = ThisWorkbook.Sh eets("Sheet2"). Cells("B,2")
'ThisWorkbook.S heets("Sheet1") .Cells("RowNumb er,3") = ThisWorkbook.Sh eets("Sheet2"). Cells("B,3")


'Sheets("Sheet2 ").Select
' Find the last row of data
'Sheets("Sheet2 ").Range("B1"). Select
'ActiveSheet.Pa ste
'Sheets("Sheet2 ").Select

End Sub
----------------------------------------------
Private Sub UserForm_Click( )

End Sub
----------------------------------------------
Private Sub UserForm_Initia lize()

TextBox1.Value = ""

End Sub
--------------------------------------------
Oct 27 '16 #1
1 902
ADezii
8,834 Recognized Expert Expert
This may not be the most effective approach, but it does work.
Expand|Select|Wrap|Line Numbers
  1. Dim strFrom As String
  2. Dim intCtr As Integer
  3. Dim shtFrom As Excel.Worksheet
  4. Dim shtTo As Excel.Worksheet
  5.  
  6. Set shtFrom = ActiveWorkbook.Worksheets("Sheet1")
  7. Set shtTo = ActiveWorkbook.Worksheets("Sheet2")
  8.  
  9. strFrom = InputBox$("Enter the From Row", "From Row")
  10.  
  11. If strFrom = "" Or Not IsNumeric(strFrom) Then Exit Sub
  12.  
  13. For intCtr = 1 To 11
  14.   Select Case intCtr
  15.     Case 1
  16.       shtTo.Range("B1") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  17.     Case 2
  18.       shtTo.Range("B2") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  19.     Case 3
  20.       shtTo.Range("B3") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  21.     Case 4
  22.       shtTo.Range("C3") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  23.     Case 5
  24.       shtTo.Range("B4") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  25.     Case 6
  26.       shtTo.Range("B5") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  27.     Case 7
  28.       shtTo.Range("B7") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  29.     Case 8
  30.       shtTo.Range("C9") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  31.     Case 9
  32.       shtTo.Range("D7") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  33.     Case 10
  34.       shtTo.Range("C7") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  35.     Case 11
  36.       shtTo.Range("D12") = shtFrom.Cells(CLng(strFrom), intCtr).Value
  37.     Case Else
  38.   MsgBox shtFrom.Cells(CLng(strFrom), intCtr).Value
  39.   End Select
  40. Next
Oct 27 '16 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
633
by: Ronny Sigo | last post by:
Hello all, Could anybody help me referencing individual cells in excel? I don't know what I do wrong here (but I'm not familiar with excel vba) (Microsoft Excel 10.0 Object library is referenced) Any help very much appreciated Thanks Ronny Private Sub btnTargetAffGroupEmailImport_Click() Dim MyXL As Object
2
7322
by: jacqueharper | last post by:
I need to change the formatting of individual cells in a datagrid. I cannot figure out how to address individual cells by their column name. I have a DataTable which contains (for instance) columns called Weight, Length and Diameter. The table is bound to a DataGrid, and I am using the ItemDataBound behavior to execute code that checks values in the table, e.g.: public void OnDataBindValuesCheck (object sender, DataGridItemEventArgs e)
3
9389
by: Christopher Lusardi | last post by:
If I want to copy one file to another how do I do that? I want to do this even if the second file already exists. Thanks, Christopher Lusardi
0
1009
by: rohithcs | last post by:
Hi, I have requirement where i need to copy group of cells in the spreadsheet or excel sheet and paste in Mail. Can anybody help me in this? I am new to VB, kindly help me out.
0
3192
by: Taxman | last post by:
Windows XP, MS Office Excel 2003 If the tasks, I’m trying accomplish have been addressed previously (separately or in combination). Please, provide the links or keyword search to find them. I’ve been searching for code for each part of the task separately and trying to piece together multiple macros, that do something similar, to what I’m trying to accomplish in my over all task, but I’m not having a lot of luck. So, here’s the entire task,...
4
4020
by: JDVOIGT | last post by:
I am building a P&L on worksheet(1) based on data from worksheet(2). I need to copy rows of data from worksheet(2) and paste onto worksheet(1). The pasting process needs to find a named range (one cell) on worksheet(1) and insert a row for the copied data above the named cell. In addition, each row on worksheet(2) must first be identified by a cell value in row (d) and be pasted to a corresponding named cell. Source = Worksheet(2) ...
3
12087
by: saums | last post by:
I want to change borderstyle of individual cells in datagridview for my current project.i found examples on 'AdjustCellBorderStyle' function on MSDN but couldn't use it.I need some help.
3
1428
by: Kappucino XL | last post by:
Hey There... I have two datasheet subforms, on a mainform: Subform1 and subform2. They receive their info from two separate tables. Now, I need to copy information from subform1 to a field in subform2. Hope my Question is clear and not too stupid...
1
1782
by: sushmanibrad | last post by:
I just want to copy the data with format from one of my excel sheet to another sheet. currently i am doing in a same way but it only copying the data but not the format in which the data is located.
0
2070
by: pka246 | last post by:
I have sql server database and i contains about 4 crore plus records. When i am copy this table into another database using SQL Server Import/Export wizard it takes 1 hours per 10 lakh records. If any fastest way can i use to copy large table to another database. I have use also use bcp utility as described in below url...but it will also take same large time. http://csharpcode.org/sql-server-bulk-insert-from-one-table-to-another/
0
7923
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8216
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8221
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6629
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
3845
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3882
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2364
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1455
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1192
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.