首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用.Cells满足条件?

如何使用.Cells满足条件?
EN

Stack Overflow用户
提问于 2020-04-17 12:58:06
回答 1查看 29关注 0票数 0

我使用用户表单向工作表中添加新内容。要添加内容,我需要一个ID号(1到...例如4,但它将用于更大的数字),并且我尝试在满足条件时发送数据(条件是,如果我在用户表单上的组合框中输入的数字与工作表上的数字相同,则用户表单上写入的所有数据将填充ID编号以下的行)。

我已经被困在这个问题上好几个小时了,就是想不出别的办法。

代码

代码语言:javascript
复制
Dim j As Long
Dim lastRow As Long
lastRow = Sheets(2).Cells(Rows.Count, "A").End(xlUp).Row
i = 0
numero = ComboBox_numero.Value 'value of the number ID filled in the combobox
    For j = 5 To lastRow
    Sheets(5).Cells(1, 2 + i) = Sheets(2).Range("A" & j).Value 'takes the ID number from an other sheet
    Select Case numero
        Case Is = Sheets(5).Cells(1, 2 + i).Value
            'here will be the data sent below the ID number
    End Select
    i = i + 1
    Next

欢迎任何帮助,我可以提供更多的细节,如果需要。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-17 13:48:08

也许你可以从这里开始:

代码语言:javascript
复制
Dim numero As Long
numero = CLng(ComboBox_numero.Value) 'value of the number ID filled in the combobox

Dim numeroPosition As Variant
numeroPosition = Application.Match(numero, Sheets(2).Range("A5", Sheets(2).Cells(Rows.Count, "A").End(xlUp)), 0) ' use Application.Match to find the index of the searched number inside the the array

If Not IsError(numeroPosition) Then ' if match found
    Sheets(5).Cells(1, numeroPosition - 2).Value = numero 'copy 'numero' in Sheets(5) wanted cell
        'here will be the data sent below the ID number
End If
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61264420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档