本文介绍了查找命名单元格的名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张受保护的工作表,其中有一些解锁的单元格供用户输入。所有这些细胞都被命名。我想创建一个宏来提取所有这些单元格中的输入并将它们导出到一个文件(最好是.txt),然后用户获取一个保存文件向导来选择
名称和位置来保存文件。另一个允许用户导入以前保存的输入的宏。

I have a protected sheet with some unlocked cell for user input. All such cells are named. I want to create a macro that extracts input in all of these cells and exports them to a file (preferable .txt) and user gets a save file wizard to choose the name and location to save the file. And another macro that lets user import previously saved input.

到目前为止,我已经使用以下代码将所有未锁定的单元格添加到范围中。

I have come so far that i add all the unlocked cells to a range using following code.


Dim rngToLook As Range
Dim rngCell As Range
Dim rngUnlocked As Range

Set rngToLook = ActiveSheet.UsedRange

For Each rngCell In rngToLook
  If rngCell.Locked = False Then
    If rngUnlocked Is Nothing Then
      Set rngUnlocked = rngCell
    Else
      Set rngUnlocked = Union(rngUnlocked, rngCell)
    End If
  Else
  End If
Next rngCell

推荐答案

Dim nme As Name

Dim nme As Name

For Each nme In Names $
 如果不是Application.Intersect(nme.RefersToRange,rngUnlocked)则没有任何内容

    MsgBox nme.Name         '返回小区名称

    MsgBox Range(nme).Value'返回指定单元格中的值

 结束如果

下一步

For Each nme In Names
  If Not Application.Intersect(nme.RefersToRange, rngUnlocked) Is Nothing Then
    MsgBox nme.Name         'Returns the cell name
    MsgBox Range(nme).Value 'Returns the value in the named cell
  End If
Next nme


这篇关于查找命名单元格的名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-26 23:45