Reputation: 57
I have those sheets. The second sheet is how I would it to be. I am now trying for hours how I would do this. Please can anyone help me on the right track.
I am copying from sheet 7(pic1) to sheet 9(pic2). The lastrow to look for should be range F.
But I always end up like in pic3.
Upvotes: 1
Views: 3689
Reputation: 57
this is the code i have for so far
Sub Test1()
Dim lrow As Long
Dim scr1 As Range 'source range
Dim scr2 As Range
Dim drng As Range 'destination range
Dim drng2 As Range
Application.ScreenUpdating = False
Sheet7.Activate
Set drng = Sheet9.Range("A3")
Set drng2 = Sheet9.Range("D3")
Set scr1 = Sheet7.Range("RecipeHeader")
scr1.Select
Selection.Copy
Sheet9.Activate
drng.End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet7.Activate
Set scr2 = Sheet7.Range("FoodCost_full")
scr2.Select
Selection.Copy
Sheet9.Activate
drng2.End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Sheet7.Range("ClearHeader").ClearContents
Sheet7.Range("Clearfood").ClearContents
Application.CutCopyMode = False
Application.ScreenUpdating = False
'lrow = Range("F" & Rows.Count).End(xlUp).Select
End Sub
Upvotes: 1
Reputation: 1255
I can't see the pictures unfortunately, so I'm not sure how on the mark I am.
In general, you want to start something like this:
Sheets("Sheet 7").Activate
Range("A1:N8").Copy
Sheets("Sheet 9").Activate
Range("A1").Paste
To select your data, and move it over. Now let's get a bit fancy.
Dim I as long
Dim J as long
Dum K as long
Dim L as long
Dim O as long
Dim P as long
I = WorkSheetFunction.Vlookup(you know how a vlookup works)
J = WorksheetFunction.Sum(You really should know this one)
.....
P = 7
Sheets("Sheet 7").Activate
Range(I&J:O&P).Copy
Sheets("Sheet 9").Activate
Range(K&L).Paste
Where you can specify the starting and ending corner of your copy range, and the starting cell of your pasting range. Use macro recorder to find out exactly how a paste values, or other type of fancy paste works.
Upvotes: 1