?
Solved

VBA - Transfer data range from 1 sheet to another by row

Posted on 2014-10-17
5
Medium Priority
?
228 Views
Last Modified: 2014-10-18
Hi

I have this excel form where i have from column B to J some values.

What i would like to do it to be able to transfer the data from B to J from Sheet1 into Sheet2 in on row 2 from column A to I when i double click on a specific row in column A.

Ex:

If on Sheet1 Range A3, i double click in it, it will transfer copy the values from B3 to I3 and paste it on sheet2 from A2 to I2.

How can i do that?

Thanks again for your help.
Test-to-transfer.xlsx
0
Comment
Question by:Wilder1626
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 1000 total points
ID: 40387584
Attached is the requested ..
Test-to-transfer.xlsm
0
 
LVL 31

Expert Comment

by:gowflow
ID: 40388632
I have a question for you:
do you always want to paste the values in Sheet2 on Row2 ? what if there is data in row2 the new doubleclik items will go on row 2 or row3 ?

The proposed solution will find the available row and paste the new data at the last available row.

here is the code for that:
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim WS2 As Worksheet
Dim WS As Worksheet
Dim MaxRow2 As Long

Set WS = ActiveSheet
Set WS2 = Sheets("Sheet2")
MaxRow2 = WS2.Range("A" & WS.Rows.Count).End(xlUp).Row + 1

If Not Intersect(Target, WS.Range("A:A")) Is Nothing Then
    WS.Range("B" & Target.Row & ":J" & Target.Row).Copy WS2.Range("A" & MaxRow2)
End If
End Sub

Open in new window


Please chk the file attached.
gowflow
Test-to-transfer-V01.xlsm
0
 
LVL 11

Author Comment

by:Wilder1626
ID: 40388669
Hi gowflow

wow, this is very good.

To answer your question, yes, it should always be on row 2 only.
0
 
LVL 31

Assisted Solution

by:gowflow
gowflow earned 1000 total points
ID: 40388729
The here it is:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim WS2 As Worksheet
Dim WS As Worksheet
Dim MaxRow2 As Long

Set WS = ActiveSheet
Set WS2 = Sheets("Sheet2")
'MaxRow2 = WS2.Range("A" & WS.Rows.Count).End(xlUp).Row + 1
MaxRow2 = 2

If Not Intersect(Target, WS.Range("A:A")) Is Nothing Then
    WS.Range("B" & Target.Row & ":J" & Target.Row).Copy WS2.Range("A" & MaxRow2)
End If
End Sub

Open in new window


and worksheet updated.
gowflow
Test-to-transfer-V01.xlsm
0
 
LVL 11

Author Closing Comment

by:Wilder1626
ID: 40388815
Hi samo4fun and gowflow.
this is perfect.

Thanks for your help
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question