根据ComboBox1选择在Worksheet中显示Textbox1中的值

时间:2017-05-17 19:04:27

标签: excel vba excel-vba

想知道是否可以帮助我将工作表中的值添加到TextBox1,具体取决于选择的ComboBox1项目。

到目前为止,我已经为我的ComboBox1提供了从我的工作表中提取列表

import UIKit
import Contacts
class ViewController: UIViewController {

override func viewDidLoad() {
    super.viewDidLoad()
    for cont in contacts {
        print(cont.givenName)
        let num = ((cont.phoneNumbers.first?.value)! as CNPhoneNumber).stringValue //CRASH
        print(num)
    }
    // Do any additional setup after loading the view, typically from a nib.
}

lazy var contacts: [CNContact] = {
    let contactStore = CNContactStore()
    let keysToFetch = [
        CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
        CNContactEmailAddressesKey,
        CNContactPhoneNumbersKey,
        CNContactImageDataAvailableKey,
        CNContactThumbnailImageDataKey] as [Any]

    // Get all the containers
    var allContainers: [CNContainer] = []
    do {
        allContainers = try contactStore.containers(matching: nil)
    } catch {
        print("Error fetching containers")
    }

    var results: [CNContact] = []

    // Iterate all containers and append their contacts to our results array
    for container in allContainers {
        let fetchPredicate = CNContact.predicateForContactsInContainer(withIdentifier: container.identifier)

        do {
            let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch: keysToFetch as! [CNKeyDescriptor])
            results.append(contentsOf: containerResults)
        } catch {
            print("Error fetching results for container")
        }
    }

    return results
}()

现在我试图让我的UserForm根据ComboBox将Worksheet中的值显示为TextBox1,但我相信我会走错路?

mycommand = "a = 5**3"
print(mycommand)
exec(mycommand)
print("a = "+str(a))

1 个答案:

答案 0 :(得分:0)

这样的事情:

Private Sub RejectTitleNm_Change()

    Dim f As Range, v

    v = Me.RejectTitleNm.Value
    'find the selected value in the source range
    Set f = Range("RejectTitle").Find(v, lookat:=xlWhole)

    Me.TextBox1.Text = ""
    If Not f Is Nothing Then
        'got a match: get value from ColB on same row
        Me.TextBox1.Text = f.EntireRow.Cells(, "B").Value
    End If

End Sub