VBA Excel 将有关范围数据的数据打印到立即窗口中以测试理解

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15832558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 15:19:43  来源:igfitidea点击:

VBA Excel Printing data into Immediate Window about a range data to test understanding

excel-vbaoutputrangevbaexcel

提问by Peter M Taylor

I am wanting to do a series of small tests that helps builds my understand as I work around a small business problem of generating data in the correct manner.

我想做一系列小型测试,以帮助我在解决以正确方式生成数据的小型业务问题时加深理解。

My first approach is to prove for myself that I could Print (string data type) a list of ID's (using the .value method) in the Immediate window of the VBE so I can see the list which I can then build up another test afterwards.

我的第一种方法是为自己证明我可以在 VBE 的立即窗口中打印(字符串数据类型)一个 ID 列表(使用 .value 方法),这样我就可以看到列表,然后我可以建立另一个测试.

My VBA code at the moment shows this which I define "CustTest" as a named Range from A1:A100 in Sheet 1

我目前的 VBA 代码显示了这一点,我将“CustTest”定义为第 1 表中 A1:A100 的命名范围

Sub TestRanges()

Dim Custrng As Range

For Each Custrng In Range("CustTest")
    Print Custrng.Value
Next
End Sub

I also thought of this

我也想到了这个

Sub TestRanges()

Dim Custrng As Range

For Each Custrng In Range("CustTest")
    With Custrng
       Print  .Value
    End With
Next
End Sub

This came up with an error I am not sure what has occured, Compile Error:- Method not valid without suitable object.

这提出了一个错误,我不确定发生了什么,编译错误:- 没有合适的对象,方法无效。

Any suggestions?

有什么建议?

Thanks, Peter.

谢谢,彼得。

回答by Kazimierz Jawor

Use: Debug.Print .Valueinstead of Print .Value

用途:Debug.Print .Value代替Print .Value

Additional information:Printis suitable to use only in Immediate window. However, we could use ?(question mark) there instead of Print

附加信息:Print仅适用于立即窗口。但是,我们可以?在那里使用(问号) 而不是Print