Solved

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

Posted on 2014-10-17
5
207 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
  • 2
  • 2
5 Comments
 
LVL 15

Accepted Solution

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

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 29

Assisted Solution

by:gowflow
gowflow earned 250 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now