简体   繁体   English

使用VBA将值粘贴到Excel中的工作表

[英]Paste values to a sheet in excel using VBA

I have already created a code wherein I search for a specific word/s in a text file and store them on a variable. 我已经创建了一个代码,其中我在文本文件中搜索特定词并将其存储在变量中。 The process of searching for these words or string is by line on the .txt file. 在.txt文件中逐行搜索这些单词或字符串的过程。

Now my problem is that I don't know how to paste that string to a sheet in excel. 现在我的问题是我不知道如何在Excel中将该字符串粘贴到工作表中。 What I want to do is that every time the code sees the word i'm looking for, it paste it to a cell in a specific worksheet, then paste the next word it finds to the cell below it, so on and so forth. 我想做的是,每次代码看到我要查找的单词时,它将其粘贴到特定工作表中的单元格中,然后将找到的下一个单词粘贴到其下方的单元格中,依此类推。

Any help would be appreciated . 任何帮助,将不胜感激 。 Thanks! 谢谢!

Assuming your variable stores strings and let's call it Variable1 for example. 假设您的变量存储了字符串,例如,我们将其称为Variable1。 Let's also assume you are storing the results in Sheet2, Column A. Would something like this help? 我们还假设您将结果存储在Sheet2的A列中。这样的帮助吗?

Sub test()
If Variable1 <> "" Then
   Sheet2.Activate
   Range("A1").End(xlDown).Offset(1, 0).Select
   ActiveCell. Value = Variable1

then add an Else or ElseIf to continue running your search, etc... 然后添加Else或ElseIf以继续运行搜索等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM