简体   繁体   English

VBA Excel ComboBox 值到范围(“特定单元格”到最后一列数据)

[英]VBA Excel ComboBox value to Range ("specific cell" to last column with data)

I am trying to fill a range of cells from a single ComboBox and I am not sure why my modified code of declaring range from cell down to last used row doesn't work when I flip it horizontally and declare range from cell to last used column on the right of the specified cell which is "C1"我正在尝试从单个 ComboBox 填充一系列单元格,我不确定为什么当我水平翻转它并声明从单元格到最后使用的列的范围时,我的修改代码从单元格到最后使用的行声明范围不起作用在指定单元格的右侧,即“C1”

    Dim LastColumn As Long
    LastColumn = Cells(1, Columns.Count).End(xlToLeft).Column

Worksheets("Machine Format").Range("C2" & LastColumn).Value = UserForm_Home.Language_ComboBox.Text

I am judging if it's the last used column by it's header row which won't be blank.我正在判断它是否是最后使用的列,它是 header 行,它不会是空白的。

Could someone, please, help me with this code?有人可以帮我处理这段代码吗?

Since you're working with the column index, use Cells instead of Range .由于您正在使用列索引,因此请使用Cells而不是Range

With Worksheets("Machine Format")
    .Range("C2", .Cells(2, LastColumn)).Value = UserForm_Home.Language_ComboBox.Text
End WIth

Use With Worksheets("Machine Format") and a period . With Worksheets("Machine Format")和句点一起使用. before Cells to properly qualify the worksheet for the Cells call.Cells之前正确限定工作表以进行Cells调用。

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

相关问题 检查哪个是特定列中最后一个具有值的单元格,然后在excel vba中选择其下方的单元格 - Check which is the last cell in a specific column which has a value and select the cell below it in excel vba 当用户在特定列范围内输入数据时,VBA 代码能否更新 Excel 工作表列中的单元格? - Can VBA code update a cell in a column of an Excel worksheet when a user enters data in a specific column range? excel vba:如何将组合框值粘贴到下一个列单元格 - excel vba: How to paste the combobox value to the next column cell 如果单元格包含VBA / Excel中的特定值,如何从范围中删除列 - How to delete column from range if cell contains specific value in VBA/Excel Excel VBA:获取包含所选范围内的数据的最后一个单元格 - Excel VBA: Get Last Cell Containing Data within Selected Range VBA 使用值设置从单元格到最后一列的范围 - VBA Set range from cell to last column with value Excel VBA:如何更改上次使用的列中单元格的值? - Excel VBA: How to change value of cell in last used column? Excel VBA 范围直到最后一个可用单元格 - Excel VBA Range until last available cell VBA 按最后一列(特定行)对动态数据范围进行排序 - VBA to sort Dynamic data range by Last Column (specific rows) 确定特定范围内的最后一个单元格并填充它,VBA - Determining the last cell in a specific range and filling it, VBA
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM