Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Copy row to sheet as per dropdown

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Copy row to sheet as per dropdown

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Copy row to sheet as per dropdown

Thanks Jacob.. Works just the way I wanted..

Can I also have the sheet name from which the row is pasted? in colI (sheet
where the row is pasted)



"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Copy row to sheet as per dropdown

Kashya, you can also avoid the loop..

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveSheet.Range("A" & lngLastRow & ":G" & lngLastRow) = arrTemp
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Copy row to sheet as per dropdown

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveWorkbook.Sheets(strSName).Range("A" & lngLastRow & ":G" & lngLastRow)
= arrTemp
ActiveWorkbook.Sheets(strSName).Range("I" & lngLastRow) = ActiveSheet.Name
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Thanks Jacob.. Works just the way I wanted..

Can I also have the sheet name from which the row is pasted? in colI (sheet
where the row is pasted)



"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Copy row to sheet as per dropdown

Oops...a mistake

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveWorkbook.Sheets(strSName).Range("A" & lngLastRow & ":G" & lngLastRow)
= arrTemp
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Jacob Skaria" wrote:

Kashya, you can also avoid the loop..

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveSheet.Range("A" & lngLastRow & ":G" & lngLastRow) = arrTemp
End If
End Sub

--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Copy row to sheet as per dropdown

Hey Jocob, this code worked..

can you help me in editing the line

lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row

I now need this to be updated in row xldown +2

Thanks..

"Jacob Skaria" wrote:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveWorkbook.Sheets(strSName).Range("A" & lngLastRow & ":G" & lngLastRow)
= arrTemp
ActiveWorkbook.Sheets(strSName).Range("I" & lngLastRow) = ActiveSheet.Name
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Thanks Jacob.. Works just the way I wanted..

Can I also have the sheet name from which the row is pasted? in colI (sheet
where the row is pasted)



"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Copy row to sheet as per dropdown

If you mean 2 rows from the last row....

lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row + 2


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hey Jocob, this code worked..

can you help me in editing the line

lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row

I now need this to be updated in row xldown +2

Thanks..

"Jacob Skaria" wrote:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveWorkbook.Sheets(strSName).Range("A" & lngLastRow & ":G" & lngLastRow)
= arrTemp
ActiveWorkbook.Sheets(strSName).Range("I" & lngLastRow) = ActiveSheet.Name
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Thanks Jacob.. Works just the way I wanted..

Can I also have the sheet name from which the row is pasted? in colI (sheet
where the row is pasted)



"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 131
Default Copy row to sheet as per dropdown

Thank you so much.. :)

"Jacob Skaria" wrote:

If you mean 2 rows from the last row....

lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row + 2


If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hey Jocob, this code worked..

can you help me in editing the line

lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row

I now need this to be updated in row xldown +2

Thanks..

"Jacob Skaria" wrote:

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
arrTemp = ActiveSheet.Range("A" & Target.Row & ":G" & Target.Row)
ActiveWorkbook.Sheets(strSName).Range("A" & lngLastRow & ":G" & lngLastRow)
= arrTemp
ActiveWorkbook.Sheets(strSName).Range("I" & lngLastRow) = ActiveSheet.Name
End If
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Thanks Jacob.. Works just the way I wanted..

Can I also have the sheet name from which the row is pasted? in colI (sheet
where the row is pasted)



"Jacob Skaria" wrote:

Set the Security level to low/medium in (Tools|Macro|Security). 'Launch VBE
using short-key Alt+F11. On the left treeview double click 'This Workbook '.
Drop down to get the SheetChange event. Save. Get back to Workbook.

Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Column = 8 Then
strSName = Cells(Target.Row, 8)
lngLastRow = ActiveWorkbook.Sheets(strSName).Cells(Rows.Count,
"A").End(xlUp).Row
For lngCol = 1 To 7
ActiveWorkbook.Sheets(strSName).Cells(lngLastRow + 1, lngCol) =
ActiveSheet.Cells(Target.Row, lngCol).Value
Next
End If
End Sub
--
If this post helps click Yes
---------------
Jacob Skaria


"Kashyap" wrote:

Hi, I have dropdown in ColH with all the names similar to sheet names. When I
select a name from dropdown macro should copy that row from A:G and paste the
same at A2 & xdown as per the sheet selected.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy dropdown list Learning VBA Excel Discussion (Misc queries) 1 January 25th 10 01:43 AM
Dropdown Sheet whatzzup Excel Discussion (Misc queries) 8 November 2nd 07 12:24 AM
How to copy Dropdown boxes? salut Excel Programming 1 December 22nd 05 06:58 PM
adding data from one sheet to another sheet as a dropdown list bo. gatorguy Excel Discussion (Misc queries) 1 February 18th 05 10:51 PM
How do I copy my dropdown box with data to another worksheet? Tess Excel Worksheet Functions 0 February 10th 05 08:33 PM


All times are GMT +1. The time now is 02:22 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"