Copy range depending on a cell values
Closed
isengard678
Posts
1
Registration date
Monday November 12, 2012
Status
Member
Last seen
November 12, 2012
-
Nov 12, 2012 at 01:56 PM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Dec 3, 2012 at 10:29 AM
TrowaD Posts 2921 Registration date Sunday September 12, 2010 Status Moderator Last seen December 27, 2022 - Dec 3, 2012 at 10:29 AM
Related:
- Copy range depending on a cell values
- An example of a cell is a blank cell ✓ - Programming Forum
- Apple airtag range - Guide
- Insert a new sheet at the end of the tab names and paste the range names starting in cell a1. autofit columns a:b and name the worksheet as range names. ✓ - Excel Forum
- Conditional formatting if cell contains text - Excel Forum
- Count if cell contains number - Excel Forum
4 responses
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Nov 13, 2012 at 10:36 AM
Nov 13, 2012 at 10:36 AM
Hi Isengard,
See if this script is to your liking:
Best regards,
Trowa
See if this script is to your liking:
Sub Test() Dim lRow, x, y As Integer Sheets("Sheet1").Select lRow = Range("A" & Rows.Count).End(xlUp).Row x = 1 Do x = x + 1 y = Range("E" & x).Value Do Range(Cells(x, "A"), Cells(x, "C")).Copy _ Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) y = y - 1 Loop Until y = 0 If Range("F" & x).Value = 1 Then Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("A" & x).Value Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("B" & x).Value Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("D" & x).Value End If Loop Until x = lRow End Sub
Best regards,
Trowa
Trowa,
thanx for the quick solution, it works as long as the value in "E" is >0 and not empty!
Any idea how I can solve this last issue?
best regards,
Kris
thanx for the quick solution, it works as long as the value in "E" is >0 and not empty!
Any idea how I can solve this last issue?
best regards,
Kris
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Nov 19, 2012 at 10:09 AM
Nov 19, 2012 at 10:09 AM
Here you go Kris:
Best regards,
Trowa
Sub Test() Dim lRow, x, y As Integer Sheets("Sheet1").Select lRow = Range("A" & Rows.Count).End(xlUp).Row x = 1 Do x = x + 1 y = Range("E" & x).Value If y = 0 Then GoTo Next_x Do Range(Cells(x, "A"), Cells(x, "C")).Copy _ Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) y = y - 1 Loop Until y = 0 If Range("F" & x).Value = 1 Then Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("A" & x).Value Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("B" & x).Value Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("D" & x).Value End If Next_x: Loop Until x = lRow End Sub
Best regards,
Trowa
Great, but now i need an extra check , "If y = 0 Then GoTo Next_x" only if the value in column f for that row = 0...
Thanks!!!
Thanks!!!
TrowaD
Posts
2921
Registration date
Sunday September 12, 2010
Status
Moderator
Last seen
December 27, 2022
555
Dec 3, 2012 at 10:29 AM
Dec 3, 2012 at 10:29 AM
Hi Isengard,
I've honored your request, but what about you comments in your 14 nov post?
Best regards,
Trowa
I've honored your request, but what about you comments in your 14 nov post?
Sub Test() Dim lRow, x, y As Integer Sheets("Sheet1").Select lRow = Range("A" & Rows.Count).End(xlUp).Row x = 1 Do x = x + 1 y = Range("E" & x).Value If y = 0 And Range("F" & x).Value = 0 Then GoTo Next_x Do Range(Cells(x, "A"), Cells(x, "C")).Copy _ Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0) y = y - 1 Loop Until y = 0 If Range("F" & x).Value = 1 Then Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("A" & x).Value Sheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("B" & x).Value Sheets("Sheet2").Range("C" & Rows.Count).End(xlUp).Offset(1, 0).Value = _ Sheets("Sheet1").Range("D" & x).Value End If Next_x: Loop Until x = lRow End Sub
Best regards,
Trowa