VBA to copy certain cells and past it to tke last row in another sheet

paroduso

Board Regular
Joined
Sep 11, 2013
Messages
103
Office Version
  1. 2019
Platform
  1. Windows
hi everyone i need help in VBA...i need to copy from sheet1 the cells T3;U3;DC37;DC41;DC45 to sheet2 and past them in B2;B3;B4;B5;B6 then when i make another copy i need to past the new data in the last row...to keep a record.thanks for the help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
try this
Code:
Sub t()
Dim sh1 As Worksheet, sh2 As Worksheet, rng As Variant
Set sh1 = Sheets(1) 'Edit sheet name
Set sh2 = Sheets(2) 'Edit sheet name
With sh1
    rng = Array(.Range("T3"), .Range("U3"), .Range("DC37"), .Range("DC41"), .Range("DC45"))
End With
For i = LBound(rng) To UBound(rng)
    sh2.Cells(i + 2, 2) = rng(i)
Next
End Sub
 
Last edited:
Upvote 0
it works but the data in sheet2 appears vertical...i need horizontal :)
can you solve it?
and one more thin when i enter new data it deletes de first entry and update...doesnt keep the first registry.
 
Last edited:
Upvote 0
I recorded this macro to copy the desired cells from Sheet1 to Sheet2 ...
how can I modify it so that when i run it copy the data ftom sheet1 to sheet2 and go adding to the last line filled ?

Sub Macro5()
'
' Macro5 Macro
'

'
Range("T3").Select
Selection.Copy
Sheets("Folha1").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("B:B").EntireColumn.AutoFit
Range("C2").Select
Sheets("H2H").Select
Range("U3").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Folha1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Columns("C:C").EntireColumn.AutoFit
Range("E2").Select
Sheets("H2H").Select
ActiveWindow.ScrollColumn = 19
ActiveWindow.ScrollColumn = 20
ActiveWindow.ScrollColumn = 22
ActiveWindow.ScrollColumn = 24
ActiveWindow.ScrollColumn = 38
ActiveWindow.ScrollColumn = 40
ActiveWindow.ScrollColumn = 41
ActiveWindow.ScrollColumn = 42
ActiveWindow.ScrollColumn = 55
ActiveWindow.ScrollColumn = 56
ActiveWindow.ScrollColumn = 57
ActiveWindow.ScrollColumn = 58
ActiveWindow.ScrollColumn = 59
ActiveWindow.ScrollColumn = 60
ActiveWindow.SmallScroll Down:=30
Range("DC37").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Folha1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("F2").Select
Sheets("H2H").Select
Range("DC41").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Folha1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("G2").Select
Sheets("H2H").Select
Range("DC45").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("Folha1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B2").Select
Sheets("H2H").Select
ActiveWindow.LargeScroll ToRight:=-3
ActiveWindow.SmallScroll Down:=-72
Range("S2").Select
End Sub

thanks
 
Upvote 0
it works but the data in sheet2 appears vertical...i need horizontal :)
can you solve it?
and one more thin when i enter new data it deletes de first entry and update...doesnt keep the first registry.
B2:B6 is vertical, if you want B2:F2 Then

Change this line
Code:
sh2.Cells(i + 2, 2) = rng(i)
To this
Code:
sh2.Cells(2, i + 2) = rng(i)
 
Upvote 0
I can't figure out what you are doing in post # 5. I am going to drop off of this thread. If you need further assistance, I suggest you collect your thoughts and start a new thread with a better explanation of what you want to do. If you can explain it, someone will assist you.
Regards, JLG
 
Upvote 0
hi JLGWhiz i want a thank you for the help....VBA its not for me :)....i have one problem solved....the data in thoes certain cells is copied from sheet1 to sheet2
horizontal...now what is missing is when i change the values in sheet1 and run the macro, i want the data to be pasted in the last row filled in sheet2...
example: cells from b2 to f2 are filled...now when i run the macro again the new data will be pasted in cells c3 to f3....and theerafter c4 to f4....c5 to f5 and so...

once more thank you...and to everyone who can help...
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,691
Members
448,978
Latest member
rrauni

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