PDA

View Full Version : Sleeper: VBA for copy from one sheet to another



ocvmelbye
11-08-2016, 01:02 AM
Hi,

I need some help making a vba code to do the following on the attached file:

When clicking the button ("Print merkostnader" on the "Utregning merkostnader" sheet) I want the following to happen:

If there is text in cell C24 in "Utregning merkostnader" sheet, copy text from cell B24, C24, H24, O24, U24 and W24.

And then check if there is text in C25 and then do the same.

Then when the loop find a cell in the C row from C24 that dont contain any text, stop the loop.


Then I want the content that is copyed to be pasted in the sheet called "Print merkostnader"
B24 paste to A9
C24 paste to B9
H24 paste to F9
O24 paste to G9
U24 paste to H9
W24 paste to I9

So after this loop is done

Copy the text from "Utregning merkostnader" B7, C7, D7 - ONLY if the cell C7 is not 0. Then do it in the range B7: D18.

Go to sheet "Print merkostnader"

Lineshift

In next available row make following headers:

In row B: Opprull
In row F: Antall meter
In row I: Total pris

Lineshift

Then paste it like this in "Print merkostnader"

B7 paste to next available B row
C7 paste to next available F row
D7 paste to next available I row





So after this loop is done

I want two line shifts and a line to sign it.

Like this:



________________________________
Place/date Signature


Thank you!

onlyadrafter
11-09-2016, 12:51 PM
Hello,

have got code that does mot of your request, but am a bit confused with:

Lineshift

Then paste it like this in "Print merkostnader"

B7 paste to next available B row
C7 paste to next available F row
D7 paste to next available I row

So after this loop is done

I want two line shifts and a line to sign it.


Sub test() With Sheets("Utregning merkostnader")
.Range("B24:W" & .Range("B" & .Rows.Count).End(xlUp).Row).Copy
End With
With Sheets("Print merkostnader")
.Range("A9").PasteSpecial (xlPasteAll)
.Columns("F:F").Delete (xlToLeft)
.Columns("G:L").Delete (xlToLeft)
.Columns("H:L").Delete (xlToLeft)
.Columns("I:I").Delete (xlToLeft)
End With
With Sheets("Utregning merkostnader")
If .Range("C7").Value <> 0 Then
.Range("B7:D7").Copy
.Range("B8:B18").PasteSpecial (xlPasteAll)
End If
End With
With Sheets("Print merkostnader")
.Range("B" & Rows.Count).End(xlUp).Offset(1, 0).Value = "Opprull"
.Range("F" & Rows.Count).End(xlUp).Offset(1, 0).Value = "Antall Meter"
.Range("I" & Rows.Count).End(xlUp).Offset(1, 0).Value = "Total Pris"
End With
End Su