Existing Code Improvement for copy and pasting

ItalianPlatinum

Well-known Member
Joined
Mar 23, 2017
Messages
793
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Is there a way I could accomplish the below with a simpler approach?
VBA Code:
With Workbooks("Compare").Sheets("C")
  rws = .Range("B2:B2").End(xlDown).row - 1
  Workbooks("Compare").Sheets("CN").Range("B2").Resize(rws, 1).Value = .Range("B2").Resize(rws).Value
End With
    
With Workbooks("Compare").Sheets("C")
  rws = .Range("E2:E2").End(xlDown).row - 1
  Workbooks("Compare").Sheets("CN").Range("F2").Resize(rws, 1).Value = .Range("E2").Resize(rws).Value
End With
        
With Workbooks("Compare").Sheets("C")
  rws = .Range("G2:G2").End(xlDown).row - 1
  Workbooks("Compare").Sheets("CN").Range("H2").Resize(rws, 1).Value = .Range("G2").Resize(rws).Value
End With
        
With Workbooks("Compare").Sheets("C")
  rws = .Range("R2:R2").End(xlDown).row - 1
  Workbooks("Compare").Sheets("CN").Range("V2").Resize(rws, 1).Value = .Range("R2").Resize(rws).Value
End With
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about:

VBA Code:
  Dim sh As Worksheet
  Dim rws As Long
  Set sh = Workbooks("Compare").Sheets("CN")
  With Workbooks("Compare").Sheets("C")
    rws = .Range("B2:B2").End(xlDown).Row - 1
    sh.Range("B2").Resize(rws, 1).Value = .Range("B2").Resize(rws).Value
    sh.Range("F2").Resize(rws, 1).Value = .Range("E2").Resize(rws).Value
    sh.Range("H2").Resize(rws, 1).Value = .Range("G2").Resize(rws).Value
    sh.Range("V2").Resize(rws, 1).Value = .Range("R2").Resize(rws).Value
  End With
 
Upvote 0
How about:

VBA Code:
  Dim sh As Worksheet
  Dim rws As Long
  Set sh = Workbooks("Compare").Sheets("CN")
  With Workbooks("Compare").Sheets("C")
    rws = .Range("B2:B2").End(xlDown).Row - 1
    sh.Range("B2").Resize(rws, 1).Value = .Range("B2").Resize(rws).Value
    sh.Range("F2").Resize(rws, 1).Value = .Range("E2").Resize(rws).Value
    sh.Range("H2").Resize(rws, 1).Value = .Range("G2").Resize(rws).Value
    sh.Range("V2").Resize(rws, 1).Value = .Range("R2").Resize(rws).Value
  End With
Dante - I apologize this is my fault I should have clarified to you better. So the file that i format has all the data needed. the only thing my file where the code is run off of is to dictate what elments to show based off of Range W in the below. there is no data being copied to the other upload file. the other file we call "upload" only has coulmn E in it located in B (and a lot of other data points). meanwhile my main file has both and looking to use that based off of column A inputs in colulmn W to format the upload. Sorry for misleading you I better depicted below where the elements are and a sample of where they would be on the upload file
Book2
ABCDEFGHIJKLMNOPQRSTUVW
1TypeNameCategorySubmissionsUnique TagIGNOREIGNORENOT NEEDEDIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNORESKUFor Export
2AA1ABC110XXXXXXAA
3AA2BBB120VVVVVCC
4AA3CCC110.5WWWWWEE
5AA4DDD122AAAAA
6BB1ACD123PPPPP
7BB2ADD145RRRSSS
8BB3AFF195TYTYT
9BB4AGG178LLLLL
10CC1LLL145UUUUU
11CC2LLL265MMMMM
12CC3LLL337BBBBB
13CC4YYY419DDDDDD
14DD2UUU882EEEEEE
15DD3PPP034QQQQQ
16DD4MNM182SSSSSS
17EE1AFD171BBBBBB
18EE2DF2117RRSARA
19
20Upload file Example
21ABCDEFGHIJKLMNOPQRSTUV
22
Sheet1
 
Upvote 0
Dante - I apologize this is my fault I should have clarified to you better. So the file that i format has all the data needed. the only thing my file where the code is run off of is to dictate what elments to show based off of Range W in the below. there is no data being copied to the other upload file. the other file we call "upload" only has coulmn E in it located in B (and a lot of other data points). meanwhile my main file has both and looking to use that based off of column A inputs in colulmn W to format the upload. Sorry for misleading you I better depicted below where the elements are and a sample of where they would be on the upload file
Book2
ABCDEFGHIJKLMNOPQRSTUVW
1TypeNameCategorySubmissionsUnique TagIGNOREIGNORENOT NEEDEDIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNOREIGNORESKUFor Export
2AA1ABC110XXXXXXAA
3AA2BBB120VVVVVCC
4AA3CCC110.5WWWWWEE
5AA4DDD122AAAAA
6BB1ACD123PPPPP
7BB2ADD145RRRSSS
8BB3AFF195TYTYT
9BB4AGG178LLLLL
10CC1LLL145UUUUU
11CC2LLL265MMMMM
12CC3LLL337BBBBB
13CC4YYY419DDDDDD
14DD2UUU882EEEEEE
15DD3PPP034QQQQQ
16DD4MNM182SSSSSS
17EE1AFD171BBBBBB
18EE2DF2117RRSARA
19
20Upload file Example
21ABCDEFGHIJKLMNOPQRSTUV
22
Sheet1
I am going to repost this to a new thread with better explanation I realize i didn't clarify my whole ask to begin with on this one
 
Upvote 0

Forum statistics

Threads
1,215,446
Messages
6,124,900
Members
449,194
Latest member
JayEggleton

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