Vb.net 在宏中从vlookup传递多个值
我已经在Excel中创建了一个名为“DisplayColumnsRows”的名称,它指的是=Sheet1$C$6:$E$36Vb.net 在宏中从vlookup传递多个值,vb.net,vba,excel,excel-2010,Vb.net,Vba,Excel,Excel 2010,我已经在Excel中创建了一个名为“DisplayColumnsRows”的名称,它指的是=Sheet1$C$6:$E$36 Column C = list of worksheet names (e.g Control) Column D = list of columns or range to display (e.g A,B,C:H) Column E = list of rows or range to display (e.g 1,2,5:10) 我创建了一个宏来查看名称“Disp
Column C = list of worksheet names (e.g Control)
Column D = list of columns or range to display (e.g A,B,C:H)
Column E = list of rows or range to display (e.g 1,2,5:10)
我创建了一个宏来查看名称“DisplayColumnsRows”中的每一行,如果C列显示工作表名称(不是空的),我希望它隐藏该工作表中的所有列和行,然后取消隐藏/显示D列中的特定列和E列中的行
到目前为止,我已经创建了以下代码,但是我一直在研究如何将值传递到ws.Range中以显示列和行
Sub Run_Me_To_Fix_Columns()
Dim ws As Worksheet
'List the names of the worksheets to exclude from Sub resizingColumns
Const excludeSheets As Variant = "Control/DIVA_Report/Asset_Details"
'Perform the following for each worksheet not excluded
For Each ws In ActiveWorkbook.Worksheets
If IsError(Application.Match(ws.Name, Split(excludeSheets, "/"), 0)) Then
Call displayColumnRow(ws)
End If
Next
End Sub
Sub displayColumnRow(ws As Worksheet)
Dim DisplayColumns As Variant
Dim DisplayRows As Variant
Dim myrange
Set myrange = Worksheets("Control").Range("range_hideColumnRow")
'Hide All Columns and Rows
ws.Columns.EntireColumn.Hidden = True
ws.Columns.EntireRow.Hidden = True
'Lookup Worksheet name and identify columns & rows to display
DisplayColumns = Application.VLookup(ws.Name, myrange, 2, False)
DisplayRows = Application.VLookup(ws.Name, myrange, 3, False)
'Display Columns and Rows (Unhide)
If Not IsError(DisplayColumns) Then
ws.Range("DisplayColumns").EntireColumn.Hidden = False
'MsgBox DisplayColumns
End If
If Not IsError(DisplayRows) Then
ws.Range("DisplayRows").EntireRow.Hidden = False
'MsgBox DisplayRows
End If
End Sub
您只需要更改输入要显示的行和列的方式——始终将列或行作为范围输入,即使它是单个列。例如,与
A,B,C:H
相反,执行以下操作:A:A,B:B,C:H
获取帮助的最佳方法是首先尝试一些东西。如果你陷入困境,做一些研究,尝试自己解决问题,然后再问一个关于你的尝试的具体问题,展示你的尝试。在没有展示研究成果的情况下提出完整解决方案的问题通常会被否决并结案。感谢您指出这一点。我已经尽了最大的努力,因此我将非常感谢任何帮助。谢谢