To use Coloumns to Paste to Sheets

btsp

Board Regular
Joined
Dec 8, 2008
Messages
102
So i have 3 Coloumns (F-H), they are checkmark coloumns.

Now i want it so that if i click Coloumn F in any row it will paste to "sheet 2".
And "sheet 3" for G and "sheet4" for H.

the range for the cloumns i have set to whatever the last row used is.

So i need to have a variable for my sheets so i cna assign them, not to sure how to get around that.

Code:
LR2 = Sheets("sheet2").Range("A" & Rows.Count).End(xlUp).Row
LR1 = Target.Row
Sheets("Sheet1").Range("A" & LR1 & ":" & "D" & LR1).Copy Destination:=Sheets("sheet2").Range("A" & LR2 + 1)


right now i have actual sheets in there just to make sure that code works. but i need that "sheet2" to become some kinda variable to point to other sheets.


thanks in advance

BTSP
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Re: To use Coloumns to Past to Sheets

I am not quite sure how you are handling if the user clicks on column I or higher but this code might give you an idea

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column > 5 And Target.Column - 4 <= Sheets.Count Then
        LR2 = Sheets("sheet" & Target.Column - 4).Range("A" & Rows.Count).End(xlUp).Row
        LR1 = Target.Row
        Sheets("Sheet1").Range("A" & LR1 & ":" & "D" & LR1).Copy _
            Destination:=Sheets("sheet" & Target.Column - 4).Range("A" & LR2 + 1)
    End If
End Sub
 
Upvote 0
Re: To use Coloumns to Past to Sheets

hmm well, my sheets im trying to copy to, are

sheet2= HONI
sheet3= IESO
sheet4= HMI


im not sure about that code, could you explain it?


i need something like

If a cell in column "F" was selected than Variable= "HONI"
If a cell in column "G" was selected than Variable= "IESO"
If a cell in column "H" was selected than Variable= "HMI"

than for this line

Code:
LR2 = Sheets(Variable).Range("A" & Rows.Count).End(xlUp).Row '
 
'Targets the row that you are clicking so it know what to copy
LR1 = Target.Row
 
'takes the range you want to copy and pastes it into the proper sheet
Sheets("Sheet1").Range("A" & LR1 & ":" & "D" & LR1).Copy Destination:=Sheets(Variable).Range("A" & LR2 + 1)

just thorw in teh variable into the sheets.

i know it doesnt work liek that ...but thats what i am thinking i need to do.
 
Upvote 0
Re: To use Coloumns to Past to Sheets

I thought you were using the names Sheet2, sheet3 etc

try this

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Column >= 6 And Target.Column <= 8 Then
    Select Case Target.Column
        Case 6
            shName = "HONI"
        Case 7
            shName = "IESO"
        Case 8
            shName = "HMI"
    End Select
LR2 = Sheets(shName).Range("A" & Rows.Count).End(xlUp).Row '
 
'Targets the row that you are clicking so it know what to copy
LR1 = Target.Row
 
'takes the range you want to copy and pastes it into the proper sheet
Sheets("Sheet1").Range("A" & LR1 & ":" & "D" & LR1).Copy Destination:=Sheets(shName).Range("A" & LR2 + 1)
End If
End Sub
 
Upvote 0
Re: To use Coloumns to Past to Sheets

that is perfect thank you ver much worked like a charm

Btsp
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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