Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Copy Values to Below last Populated Cell Q

I am trying to copy values in Trade up Meals cells A9; B9; J18; K18; L18;
N18; O18 (and for every 12th Row below these values) to a sheet called
Ingredient Products starting on the row below the last populated cell.

I am using the following code but am getting very unreliable data, does the
code look ok?

Thanks

Sub TradeupCostToIngredients_Post()
Dim I As Long, j As Long, k As Long, l As Long
Dim rng As Range, cell As Range
With Worksheets("Trade Up Meals")
Set rng = Union(.Range("A9"), .Range("B9"), .Range("J18"), .Range("K18"),
..Range("L18"), .Range("N18"), .Range("O18"))

I = 0
j = 0
l = 0
For Each cell In rng
j = cell.Row
l = l + 1
k = Worksheets("Ingredient Products").Cells(Rows.Count,
l).End(xlUp).Row + 1
Do While Not IsEmpty(.Cells(j, cell.Column))
.Cells(j, cell.Column).Copy
Worksheets("Ingredient Products") _
.Cells(k, l).PasteSpecial xlValues
k = k + 1
j = j + 12
Loop
Next
End With

Sheets("Ingredient Products").Select

Columns("B:B").Select
Columns("B:B").EntireColumn.AutoFit

Columns("C:G").Select
Application.CutCopyMode = False
Selection.NumberFormat = "#,##0.00"
Range("A1").Select

Set rng = Range("A1:G1").Resize(Cells(Rows.Count, "A").End(xlUp).Row, 7)
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select

Sheets("Master").Select
Range("A1").Select

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Copy Values to Below last Populated Cell Q

John,

Try the code below to see if it improves your results.

HTH,
Bernie
MS Excel MVP

Sub TradeupCostToIngredients_Post2()
Dim i As Long
Dim myStartRow As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim mySht As Worksheet

Set mySht = Worksheets("Ingredient Products")

myStartRow = mySht.Cells(mySht.Rows.Count, 1).End(xlUp)(2).Row

With Worksheets("Trade Up Meals")
Set Rng1 = Union(.Range("A9"), .Range("B9"))
Set Rng2 = Union(.Range("J18"), .Range("K18"), _
.Range("L18"), .Range("N18"), .Range("O18"))

For i = 0 To .Range("A65536").End(xlUp).Row Step 12
Set Rng1 = Union(Rng1, Rng1.Offset(i, 0))
Next i

Rng1.Copy mySht.Cells(myStartRow, 1)

For i = 0 To .Range("A65536").End(xlUp).Row Step 12
Set Rng2 = Union(Rng2, Rng2.Offset(i, 0))
Next i

Rng2.Copy mySht.Cells(myStartRow, 3)

End With

With Sheets("Ingredient Products")
.Columns("B:B").AutoFit
.Columns("C:G").NumberFormat = "#,##0.00"
.Range("A1").CurrentRegion.Sort Key1:=.Range("A1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("A1").Select
End With
End Sub

"John" wrote in message
...
I am trying to copy values in Trade up Meals cells A9; B9; J18; K18; L18;
N18; O18 (and for every 12th Row below these values) to a sheet called
Ingredient Products starting on the row below the last populated cell.

I am using the following code but am getting very unreliable data, does

the
code look ok?

Thanks

Sub TradeupCostToIngredients_Post()
Dim I As Long, j As Long, k As Long, l As Long
Dim rng As Range, cell As Range
With Worksheets("Trade Up Meals")
Set rng = Union(.Range("A9"), .Range("B9"), .Range("J18"), .Range("K18"),
.Range("L18"), .Range("N18"), .Range("O18"))

I = 0
j = 0
l = 0
For Each cell In rng
j = cell.Row
l = l + 1
k = Worksheets("Ingredient Products").Cells(Rows.Count,
l).End(xlUp).Row + 1
Do While Not IsEmpty(.Cells(j, cell.Column))
.Cells(j, cell.Column).Copy
Worksheets("Ingredient Products") _
.Cells(k, l).PasteSpecial xlValues
k = k + 1
j = j + 12
Loop
Next
End With

Sheets("Ingredient Products").Select

Columns("B:B").Select
Columns("B:B").EntireColumn.AutoFit

Columns("C:G").Select
Application.CutCopyMode = False
Selection.NumberFormat = "#,##0.00"
Range("A1").Select

Set rng = Range("A1:G1").Resize(Cells(Rows.Count, "A").End(xlUp).Row,

7)
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending,

Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select

Sheets("Master").Select
Range("A1").Select

End Sub





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Copy Values to Below last Populated Cell Q

Thanks Bernie

"Bernie Deitrick" <deitbe @ consumer dot org wrote in message
...
John,

Try the code below to see if it improves your results.

HTH,
Bernie
MS Excel MVP

Sub TradeupCostToIngredients_Post2()
Dim i As Long
Dim myStartRow As Long
Dim Rng1 As Range
Dim Rng2 As Range
Dim mySht As Worksheet

Set mySht = Worksheets("Ingredient Products")

myStartRow = mySht.Cells(mySht.Rows.Count, 1).End(xlUp)(2).Row

With Worksheets("Trade Up Meals")
Set Rng1 = Union(.Range("A9"), .Range("B9"))
Set Rng2 = Union(.Range("J18"), .Range("K18"), _
.Range("L18"), .Range("N18"), .Range("O18"))

For i = 0 To .Range("A65536").End(xlUp).Row Step 12
Set Rng1 = Union(Rng1, Rng1.Offset(i, 0))
Next i

Rng1.Copy mySht.Cells(myStartRow, 1)

For i = 0 To .Range("A65536").End(xlUp).Row Step 12
Set Rng2 = Union(Rng2, Rng2.Offset(i, 0))
Next i

Rng2.Copy mySht.Cells(myStartRow, 3)

End With

With Sheets("Ingredient Products")
.Columns("B:B").AutoFit
.Columns("C:G").NumberFormat = "#,##0.00"
.Range("A1").CurrentRegion.Sort Key1:=.Range("A1"), _
Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
.Range("A1").Select
End With
End Sub

"John" wrote in message
...
I am trying to copy values in Trade up Meals cells A9; B9; J18; K18;

L18;
N18; O18 (and for every 12th Row below these values) to a sheet called
Ingredient Products starting on the row below the last populated cell.

I am using the following code but am getting very unreliable data, does

the
code look ok?

Thanks

Sub TradeupCostToIngredients_Post()
Dim I As Long, j As Long, k As Long, l As Long
Dim rng As Range, cell As Range
With Worksheets("Trade Up Meals")
Set rng = Union(.Range("A9"), .Range("B9"), .Range("J18"),

..Range("K18"),
.Range("L18"), .Range("N18"), .Range("O18"))

I = 0
j = 0
l = 0
For Each cell In rng
j = cell.Row
l = l + 1
k = Worksheets("Ingredient Products").Cells(Rows.Count,
l).End(xlUp).Row + 1
Do While Not IsEmpty(.Cells(j, cell.Column))
.Cells(j, cell.Column).Copy
Worksheets("Ingredient Products") _
.Cells(k, l).PasteSpecial xlValues
k = k + 1
j = j + 12
Loop
Next
End With

Sheets("Ingredient Products").Select

Columns("B:B").Select
Columns("B:B").EntireColumn.AutoFit

Columns("C:G").Select
Application.CutCopyMode = False
Selection.NumberFormat = "#,##0.00"
Range("A1").Select

Set rng = Range("A1:G1").Resize(Cells(Rows.Count,

"A").End(xlUp).Row,
7)
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending,

Header:=xlGuess,
_
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A1").Select

Sheets("Master").Select
Range("A1").Select

End Sub







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 to new cells if populated srbow Excel Discussion (Misc queries) 1 April 30th 09 06:25 PM
Copy values from a cell based on values of another cell Spence10169 Excel Discussion (Misc queries) 4 January 13th 09 10:01 AM
copy last populated cell (moving) to another cell robert morris Excel Discussion (Misc queries) 1 August 23rd 08 10:16 PM
First populated cell in row array/ Last populated cell in row arra Skyscan Excel Worksheet Functions 7 May 29th 08 05:20 PM
using IF function to copy, but leave populated cell alone [email protected] Excel Worksheet Functions 5 May 12th 06 10:39 PM


All times are GMT +1. The time now is 06:56 AM.

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"