限制Userform对特定Excel单元格中的值的响应

时间:2016-10-01 17:07:41

标签: excel vba userform

我在excel中创建了一个VBA用户表单,我希望将标记为“日期”的文本框中输入的内容限制为另一个工作表中单元格中列出的日期列表。

这可能吗?或者从特定单元格填充列表框?

2 个答案:

答案 0 :(得分:1)

最好使用ComboBoxListBox控制而不是TextBox

Option Explicit

Sub main()

    With MyUserForm '<--| change "MyUserForm" to your actual userform name
        .DatesCB.List = GetDates '<--| change "DatesCB" to your actual dates ComboBox name
        .Show
    End With

End Sub

Function GetDates()
    With Worksheets("Dates") '<--| reference "Dates" worksheet (change "Dates" to your actual dates worksheet name)
        GetDates = Application.Transpose(.Range("A2", .Cells(.Rows.Count, "A").End(xlUp)).Value) '<--|change "A"'s to your actual column index with dates
    End With
End Function

答案 1 :(得分:1)

将Comboboxs或Listboxs的Rowsource属性设置为Range的外部地址将使用范围的值填充控件。这适用于单列或多列范围。

export const init = () => {
world = new CANNON.World();
world.gravity.set(0,1,0);
world.broadphase = new CANNON.NaiveBroadphase();
world.solver.iterations = 10;

for (let i = 0; i < BODIES_COUNT; i++) {
    const shape = new CANNON.Box(new CANNON.Vec3(4,4,4));
    const body = new CANNON.Body({
        mass: 1,
    });
    const body = new CANNON.Body();
    body.addShape(shape);
    body.position.set(0, 0, 0);
    body.mass = 1;
    body.angularVelocity.set(0, 2, 0);
    body.velocity.set(0, 1, 0);
    body.angularDamping = 0.5;

    world.addBody(body);
    bodies.push(body);

    const geometry = new THREE.BoxGeometry(10, 10, 10);
    const material = new THREE.MeshBasicMaterial({ color: 0xff0000, wireframe: true });
    const mesh = new THREE.Mesh(geometry, material);
    meshes.push(mesh);
}
}

export const update = (delta) => {
    world.step(TIMESTEP * delta);
}