简体   繁体   English

如何在Excel公式中为列表附加字符串(DropDown)

[英]How to append a string in excel formula for a list (DropDown)

I have a drop-down in sheet2 at cell F6 which contains a list from sheet1 with formula =Sheet1!$1:$1 and it gives me a drop with list of values like Header1,Header2,Header3,Header4,.. . 我在单元格F6 sheet2中有一个下拉列表,其中包含sheet1具有公式=Sheet1!$1:$1列表,它为我提供了包含诸如Header1,Header2,Header3,Header4,..列表。 What I want to achieve is these values should be like [Header1],[Header2],[Header3],.. Is there some way to achieve using excel formulas or VBA (apart from array with for loop). 我要实现的是这些值应类似于[Header1],[Header2],[Header3],..是否有某种方法可以使用excel公式或VBA(除了带有for循环的数组)。 I'm searching for something like "["&=Sheet1!$1:$1 &"]" . 我在搜索类似"["&=Sheet1!$1:$1 &"]"

Done it with below code (in case if anyone need a reference for How to read a Row in excel VBA) 使用以下代码完成此操作(以防万一,如果有人需要有关如何在excel VBA中读取行的参考)

    Dim objSheet As Worksheet
    Set objSheet = Sheets(1)
    Dim intLastCellIndexInRow As Integer
    intLastCellIndexInRow = ActiveCell.SpecialCells(xlLastCell).Column
    Dim i As Integer
    Dim strRowValue As String

    For i = 1 To intLastCellIndexInRow
      If objSheet.Cells(1, i) <> "" Then
        strRowValue = strRowValue & ",[ " & objSheet.Cells(1, i) & "]"
      End If
    Next

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM