开发者

Excel macro - merging fields and adding a value

开发者 https://www.devze.com 2023-02-16 18:50 出处:网络
I have written a piece of code, it copies the data from the entire cells and pastes this into another file.

I have written a piece of code, it copies the data from the entire cells and pastes this into another file.

    Select Case Range("A2").Value
    Case 3
        Sheets("Info").Select
        Range("A1").Copy Destination:=Sheets("Design").Range("B1")
    End Select
开发者_如何学运维

Example of what I'm trying to do;

1.xls
Cell A1: Black Jack
Cell A2: 3

This gets copied and pasted in

2.xls
Cell B1: Black Jack

Now how can I insert the information from A2 into B1 aswell to get something along the lines of

Cell B1: Black Jack - 3x

Also the source formatting gets changed, it should be Century Gothic, 12 but changes to Calibri, 11.

Thank you!!


Don't use copy. Be explicit like this:

Sheets("Design").Range("B1").Value = Range("A1").Value & " - " & Range("A2").Value & "x"

This will only copy the values and no fonts will be harmed in the process.

0

精彩评论

暂无评论...
验证码 换一张
取 消