如何仅使用VBA复制值 [英] How to only copy values using VBA

查看:446
本文介绍了如何仅使用VBA复制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要将没有公式的值从工作表复制到另一个.以下代码确实复制但仅与公式一起复制.我尝试了该网站上提供的一些解决方案,但它们给了我错误.

I need to copy values only without Formula from sheet to another. The following code does copy but only with Formula. I tried some solutions presented in this site but they give me errors.

For i = 2 To LastRow
    'sheet to copy from
   With Worksheets("Hoist")
        'check column H value before copying
       If .Cells(i, 8).Value >= -90 _
       And CStr(.Cells(i, 9).Value) <> "Approved" _
       And CStr(.Cells(i, 9).Value) <> "" _
       And CStr(.Cells(i, 10).Value) = "" Then
            'copy row to "display" sheet
           .Rows(i).Copy Destination:=Worksheets("display").Range("A" & j)
           j = j + 1
       End If
   End With
Next i

推荐答案

尝试更改此行:

.Rows(i).Copy Destination:=Worksheets("display").Range("A" & j)

对此:

.Rows(i).Copy
Worksheets("display").Range("A" & j).PasteSpecial xlPasteValues

这将删除所有格式.要包括格式设置,您需要添加另一行,例如:

This however drops all formatting. To include formatting, you'll need to add another line like:

Worksheets("display").Range("A" & j).PasteSpecial xlPasteFormats

这篇关于如何仅使用VBA复制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆