如何将单元格值从表传递到组合框?

问题描述

我正在尝试在Excel VBA中构建表单。我已经建立了表单,但是我希望用户能够编辑表单中的数据。我希望用户能够输入参数,然后表单将搜索表以查看参数是否存在。如果是这样,则表单将使用该行中的数据填充。

我不知道为什么这段代码行得通,但是我似乎无法取出单元格中的数据。从手表中可以看到,正在选择正确的单元格。但是单元格不会分配给我的变量或组合框。这就是我到目前为止所得到的!

Public Function LoadFormEdit(Row As Integer)
Dim rng As Range
Dim RowNum As Integer
RowNum = Row
Dim lookupValue As String
'Set the range to be the table we want to work with
Set rng = ThisWorkbook.Worksheets("MyWorksheet").Range("MyDataTable")

Dim ColOffset As Integer
ColOffset = rng.Column - 1

'Add the selections to the ComboBox,and make visible
Me.MyComboBox.Visible = True
lookupValue = rng.Cells(RowNum,6).Text
Me.MyComboBox.value = lookupValue

非常感谢您的帮助!

解决方法

以真正的堆栈溢出方式,我在发布它后就弄清楚了。

问题是我没有正确地考虑到我的表不在工作表中的1,1的事实。因此,以下代码修复了问题:

Public Function LoadFormEdit(Row As Integer)
Dim rng As Range
Dim RowNum As Integer
Dim RowOffset As Integer
Dim lookupValue As String

'Set the range to be the table we want to work with
Set rng = ThisWorkbook.Worksheets("MyDataSheet").Range("MyDataTable")
RowOffset = rng.Row - 1
RowNum = Row - RowOffset


'Add the selections to the ComboBox,and make visible
Me.MyComboBox.Visible = True
lookupValue = rng.Cells(RowNum,5).value
Me.MyComboBox.value = lookupValue

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...