How to transfer specific data from one excel sheet to another in MS Excel?

Viewed 105

Basically, I have two excel sheets. What I am trying to do is to copy specific cell value from current cell to another. Let say, I have a form sheet of cash deposits:

Cash deposits form info: enter image description here

and then, I need to copy and paste some of the data needed to another form.

This is the form where I want to paste the cell value from cash deposits:

enter image description here

I tried Macro but I have a limited knowledge about it and it seems difficult for me. any idea?

2 Answers
Sub move_data()

Dim main_sheet As String
Dim target_sheet As String

Dim info1 As String
Dim target_info1 As String

Dim info2 As String
Dim target_info2 As String

'CONFIG
'--------------------------
main_sheet = "Sheet1" 'set sheet name to copy from
target_sheet = "Sheet2" 'set sheet name to paste in

'cells to copy
info1 = "A1"
info2 = "B1"

'cells to paste
target_info1 = "B1"
target_info2 = "B2"
'----------------------

Sheets(target_sheet).Range(target_info1) = _
Sheets(main_sheet).Range(info1)

Sheets(target_sheet).Range(target_info2) = _
Sheets(main_sheet).Range(info2)

End Sub

If you need to copy/paste more cells, just add more String variables as info1 and info2 with their correspoding target cell to paste in and add the following code before the End Sub making the corresponding changes in the variable names.

Sheets(target_sheet).Range(target_info2) = _
Sheets(main_sheet).Range(info2)

The way to copy the values of one set of cells into another is as follows:

Say you want to copy the range "A2:G101" (100×7 table) from Sheet1 to "F2:L101" (100×7 table) of Sheet2

Sheet2.Range("F2").Resize(100,7).Value = Sheet1.Range("A2").Resize(100,7).Value

In other posts you will see the .Value omitted because it is the default property, but it is not recommended to do so because it hides the intent of the code.

The above works with [named ranges] in the Range() specification as well as "A1" style referencing. The .Resize() command expands the reference from one cell to multiple rows and columns (given as rows, columns).

Related