Copy values and numberformat from one range to ano

2019-09-17 09:56发布

I got no error with the line below where I copy the values from one range to another:

ThisWorkbook.Sheets("Output").Range("F" & lastRowOutput + 1 & ":" & "M" & lastRowOutput + 1).Value = projectWb.Sheets("Beställningar").Range("B" & row & ":" & "I" & row).Value

But when I try to do the same with the NumberFormat I get an error message:

ThisWorkbook.Sheets("Output").Range("F" & lastRowOutput + 1 & ":" & "M" & lastRowOutput + 1).NumberFormat = projectWb.Sheets("Beställningar").Range("B" & row & ":" & "I" & row).NumberFormat

What I really want to achieve is to copy values from one range to another, and retain the text values as text and number values as numbers.

2条回答
Lonely孤独者°
2楼-- · 2019-09-17 10:24

You can get the general idea by simply recording a macro:

Range("C12:C13").Select
Selection.Copy
Range("G12").Select
Selection.PasteSpecial Paste:=xlPasteValuesAndNumberFormats, Operation:= _
    xlNone, SkipBlanks:=False, Transpose:=False
查看更多
叛逆
3楼-- · 2019-09-17 10:25

Try this one:

projectWb.Sheets("Beställningar").Range("B" & Row & ":" & "I" & Row).Copy
ThisWorkbook.Sheets("Output").Range("F" & lastRowOutput + 1).PasteSpecial xlPasteValuesAndNumberFormats
查看更多
登录 后发表回答