如何将值打印到下一个空行单元格中? [英] How to print values into next empty row cells?

查看:52
本文介绍了如何将值打印到下一个空行单元格中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了一个VBA表单来收集用户的数据.但是,我希望允许用户多次填写表单,并且每次将填写的数据打印到Excel工作表中的适当单元格中,因此我希望VBA程序在用户不希望的情况下在工作表中查找下一个空单元格手动查看并选择它.

I have designed a VBA form to collect data from the user. However, I want to allow the user to fill the form multiple times and each time prints the filled out data into appropriate cells in the Excel sheet, so I want the VBA program to look for the next empty cell in the sheet without having the user to look manually and select it.

Cells(lastRow, 1) = emplName
Cells(lastRow, 2) = depTxt
Cells(lastRow, 3) = emplNo
Cells(lastRow, 4) = mngrName
Cells(lastRow, 5) = ComboBox1.Value

例如,这五个值应随后打印到第一行,如果再次使用该表单,则应找到下一个空行以打印这些值.

Here for instance, these five values should then print into the first row, if the form is used again, it should find the next empty row to print the values.

谢谢您的时间.

推荐答案

有很多方法可以使用VBA在Excel中选择/检测最后一行.我通常使用的最好的一个:

There are quite a few ways to select/detect last row in Excel with VBA. The best one I usually use:

Function LastRow(wsName As String, Optional columnToCheck As Long = 1) As Long
    Dim ws As Worksheet
    Set ws = Worksheets(wsName)
    LastRow = ws.Cells(ws.Rows.Count, columnToCheck).End(xlUp).Row
End Function

这是将其用于"E"列(第5列)的方法:

This is how to use it for column "E" (5th column):

someLastRow = LastRow("WorksheetName",5)

如果您有改进的想法,请随时进行PR: https://github.com/Vitosh/VBA_personal/blob/master/LastThings.vb

If you have ideas for improvement, feel free to make PR: https://github.com/Vitosh/VBA_personal/blob/master/LastThings.vb

这篇关于如何将值打印到下一个空行单元格中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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