Transfer info from one sheet to another depending on cell input

manmah

Board Regular
Joined
May 11, 2009
Messages
70
Hi there

Think I should change my user name to 'stumped again!!'

I am wanting to transfer data from one sheet to another depending on cell input

example:

If I enter "2" in sheet1 cell B1, then I want a macro to take A1 to sheet2 but place it in A1 & A2.
then say I enter "1" in sheet1 cell B2 goto sheet2 and put A2 into A3 and so on.

Depending on the number entered on sheet1 column B, the Macro duplicates the info from Column A in that row into column A on sheet2. ?????:confused:

Thanks in advance

Mark
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Hi Mark,

Try this, copy the code to Sheet1 code window
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

    Dim lEmptyRow As Long, LCounter As Long

    If Target.Column = 2 And Target.Count = 1 Then
        If Target <= 0 Then Exit Sub
        With Sheets("Sheet2")
            If .Range("A1") = "" Then
                lEmptyRow = 1
            Else
                lEmptyRow = .Range("A" & .Rows.Count).End(xlUp).Offset(1).Row
            End If
            For LCounter = 1 To Target
                .Cells(lEmptyRow + LCounter - 1, "A") = Target.Offset(, -1)
            Next LCounter
        End With
    End If

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0
You'e welcome.. one more quick question tho, i've been fiddling around and just wondered what I would change in the code if I have another column in between. eg - my number in M and the info to copy in K??


Thanks
Mark
 
Upvote 0

Forum statistics

Threads
1,203,472
Messages
6,055,612
Members
444,803
Latest member
retrorocket129

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