473,378 Members | 1,447 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Copy and pasting entries from one sheet to another based on Column Value

My task is to enter on one cell of a first worksheet (ROW) is transpose to the correspond cell on the other sheet. For Example; any edits made to Line 47 on the ROW sheet must automatically be replicated on Line 43 on Japan’s second worksheet. Therefore any one inputting data and making changes to the format will be automatically be updated on the corresponding Column in Japan’s sheet.
If we compare the ROW sheet to Japan’s sheet we can see only a selected number of values in column C are the same; not all the Values on the ROW Sheet is present on Japan’s sheet.

Expand|Select|Wrap|Line Numbers
  1. Sub CopyCells()
  2.       Application.ScreenUpdating = False
  3.     Dim sh1 As Worksheet, sh2 As Worksheet
  4.   Dim j As Long, i As Long, lastrow1 As Long, lastrow2 As Long
  5.   Set sh1 = Worksheets("ROW")
  6.  Set sh2 = Worksheets("Japan")
  7.  lastrow1 = sh1.Cells(Rows.Count, "C").End(xlUp).Row
  8.  
  9.  lastrow2 = sh2.Cells(Rows.Count, "C").End(xlUp).Row
  10.      For i = 5 To lastrow1
  11.    For j = 5 To lastrow2
  12. If sh1.Cells(i, "C").Value = sh2.Cells(j, "C").Value Then
  13.               sh1.Cells(i, "C").Value = sh2.Cells(j, "C").Value
  14.     Application.CutCopyMode = False
  15.        End If
  16.       Next j
  17.  Next i
  18.  Application.ScreenUpdating = True
  19. End Sub
Sep 19 '11 #1
7 2779
The Line sh1.Cells(i, "C").Value = sh2.Cells(j, "C").Value should copy the row and paste it another sheet.But don't know What is missing? I am able to match the criteria but not able to paste the rows.
Sep 19 '11 #2
Mihail
759 512MB
I don't understand very well your task.
But here you are a tip:

Start a new macro.
Make your own the operations: SELECT from sh1 -> COPY -> SELECT in sh2 -> PASTE.
Stop the macro.
Edit the macro see the exact syntax and/or work around this code (use the code generate by Excel as a template).

Note that
Expand|Select|Wrap|Line Numbers
  1. sh1.cells(Row1,Column1)= sh2.cells(Row2,Column2)
will NOT copy the cell from sh2 to sh1.
This line of code will get to left side cell only the VALUE(not format, comments or anything else) from the right side cell.

If this not help you, post your workbook and I'll try to solve this for you. (I use Excel 2007 but I can save in a previous version if you need).

Good luck !
Sep 20 '11 #3
Thanks for replying!!Well I tried all damn things in VBA to do this task.Just want to replace the contents of entire row of sheet1 with formats to same row of sheet2.

Expand|Select|Wrap|Line Numbers
  1. Sub CopyCells()
  2.       Application.ScreenUpdating = False
  3.     Dim sh1 As Worksheet, sh2 As Worksheet
  4.   Dim j As Long, i As Long, lastrow1 As Long, lastrow2 As Long
  5.   Set sh1 = Worksheets("ROW")
  6.  Set sh2 = Worksheets("Japan")
  7.  lastrow1 = sh1.Cells(Rows.Count, "C").End(xlUp).Row
  8.  
  9.  lastrow2 = sh2.Cells(Rows.Count, "C").End(xlUp).Row
  10.      For i = 5 To lastrow1
  11.    For j = 5 To lastrow2
  12. If sh1.Cells(i, "C").Value = sh2.Cells(j, "C").Value Then
  13.               'sh1.Cells(i, "B").Value = sh2.Cells(j, "C").Value
  14.                  sh1.Range("C" & i).Value = sh2.Range("C" & j).Value
  15.                  sh1.Activate
  16.                  sh1.Range("C" & i).Select
  17.                  Selection.Copy
  18.                  sh2.Activate
  19.                  sh2.Range("C" & j).Select
  20.               'ActiveSheet.Paste
  21.              ' ActiveSheet.Paste Destination:=Worksheets("Japan").Cells(j, "C")
  22.  
  23. Application.CutCopyMode = False
  24. With Selection
  25. .MergeCells = False
  26. End With
  27.  
  28. 'Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  29. Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
  30.  
  31.  
  32.                  ' Selection.Range("C" & j).PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
  33.            ' :=False, Transpose:=False
  34.                 ' MsgBox " " & sh1.Range("C" & i).Value = sh2.Range("C" & j).Value & ""
  35.  
  36.        End If
  37.       Next j
  38.  Next i
  39.  Application.ScreenUpdating = True
  40. End Sub
Sep 20 '11 #4
Rabbit
12,516 Expert Mod 8TB
The column parameter of the Cells array uses integers as inputs, not characters.
Sep 20 '11 #5
ADezii
8,834 Expert 8TB
@Rabbit: The Index need not be Numeric,
Expand|Select|Wrap|Line Numbers
  1. Worksheets("Sheet1").Cells(1, 3) = "Hello World"
  2. Worksheets("Sheet1").Cells(1, "C") = "Hello World"
will both work.
Sep 20 '11 #6
Mihail
759 512MB
To copy row 14 from sheet_1 to sheet_2:
Expand|Select|Wrap|Line Numbers
  1.     Sheets("Sheet1").Select
  2.     Rows("14:14").Select
  3.     Selection.Copy
  4.     Sheets("Sheet2").Select
  5.     Range("A14").Select
  6.  
  7.     ' Only formats
  8.     Selection.PasteSpecial Paste:=xlPasteFormats
  9.  
  10.     ' All (formats and values)
  11.     Selection.PasteSpecial Paste:=xlPasteAll
or to transpose row 14 into column 14 ("N"):
Expand|Select|Wrap|Line Numbers
  1.     Sheets("Sheet1").Select
  2.     Rows("14:14").Select
  3.     Selection.Copy
  4.     Sheets("Sheet2").Select
  5.     Range("N1").Select
  6.     Selection.PasteSpecial Paste:=xlPasteAll, Transpose:=True
Note that ALL this code was generated by Excel using Record Macro option.
I copy-paste it for you.

If you still are not able to do the job, attache your workbook to the next post and will see.

Good luck !
Sep 21 '11 #7
NeoPa
32,556 Expert Mod 16PB
If you can manage to explain what you're trying to do so that it starts to make sense then I'll look at it for you. Unfortunately it seems we're all trying to guess what you're on about and none of us has much of an idea it seems.

In the mean time I will tidy up all the posts without the mandatory CODE tags and hope you won't post any more that way in future (as it justs wastes more time).
Sep 26 '11 #8

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

Similar topics

3
by: M | last post by:
I am trying to copy the values of one hashtable to another. I ran into a read only error when using the IDictionaryEnumerator. while (myHashEnumerator.MoveNext()){ while...
3
by: newsgroper | last post by:
I am evaluating the infragistice ultrawingrid. Does anyone know how I can color a row based upon a column value?
0
by: Amber | last post by:
There are times when you will need to highlight or otherwise modify the contents of a particular DataGrid row-column value based upon the value in the column. In this example we will select the...
17
by: emma.sax | last post by:
Hi all, I have a form where we would like the user to input their email address twice, to ensure they've typed it correctly, as is found on most sign-ups I'm looking for a solution to the...
1
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm populating a datagridview from a data table. I would like to set the back ground color of each row based on a column value in that row. If the value of a column for a particular row is set...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
0
by: Joe Meng | last post by:
Greetings, I've seen this question asked and answered here, just not completely yet. I'm wondering how to use a column value as a table name in another query. So far it's looking like you must...
0
by: sk27ahmed | last post by:
Hi Any one can show me how to access datagridview column value on column checked unchecked. I create one column in datagridview of type checkbox,and on button click i write code to select all...
3
by: hauschild | last post by:
Guys, I am looping thru a dataset and need to update rows' columns based on the ColumnName value. I get this far but I'm unsure of how to update that actual columns value with the new value. ...
2
by: harichinna | last post by:
Hi to all, My name is hari, iam trying to delete the column value of spread sheet using c sharp, iam trying to get the value and compare, when comparing it showing some errors, can any one help...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.