简体   繁体   English

使用 vba excel 2010 写入工作表

[英]Writing to a worksheet using vba excel 2010

I am new to programming so please forgive me if this problem is easy.我是编程新手,所以如果这个问题很简单,请原谅我。

I am writing data obtained from a userform to a worksheet.我正在将从用户表单获得的数据写入工作表。 Row 1 is used fir headings so the data would be entered at row2 if row 2 is used I would like to write to the following row.第 1 行用于 fir 标题,因此如果使用第 2 行,数据将在第 2 行输入我想写入下一行。

Just now I have code that finds the next empty row on the worksheet.刚才我有代码可以找到工作表上的下一个空行。 I have headings half way down the worksheet to display something separate but because of the search cell code I am using it writes the data that should be at the top of the worksheet under the headings I have half way down the page.我在工作表的中间有标题以显示单独的内容,但由于我使用的搜索单元格代码,它会将应位于工作表顶部的数据写入页面中间的标题下。

I am just looking to start writing at A2 then onto the next row.我只是想从 A2 开始写作,然后再到下一行。

Cheers in advance for your help.提前为您的帮助干杯。

Craig克雷格

If I understand what I think you are trying to do then there are a couple of ways you can do this.如果我理解我认为您正在尝试做的事情,那么有几种方法可以做到这一点。 You can loop through the cells which has it's uses but is considered inefficient :您可以遍历具有其用途但被认为效率低下的单元格:

Range("A2").Select

Do
  ActiveCell.Offset(1, 0).Select
Loop Until ActiveCell.Value = ""

ActiveCell.Value = "YourValue"

The most efficient way would probably be to use the xlDown command:最有效的方法可能是使用 xlDown 命令:

Range("A2").Select

ActiveCell.End(xlDown).Offset(1, 0).Value = "Different Way"

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

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