读取VBA中Row中的所有值

时间:2023-01-16 12:42:44

I want to read out all values in the header searching for a defined value

我想读出标题中搜索定义值的所有值

For i_col = column_a To column_z
 Set search = Wks1.Cells(i_col&"1")
 If search.Value = "" Then

So I saw possibilities like creating an array or tranpose all, but I'm searching for an easier way

所以我看到了创建数组或全部转换的可能性,但我正在寻找一种更简单的方法

I think this was frequendly asked, but I didn't found a good solution

我认为这是常见的问题,但我没有找到一个好的解决方案

2 个解决方案

#1


0  

For this purpose, you can use FIND method like below without using a loop:

为此,您可以使用如下所示的FIND方法而不使用循环:

set rngSearch = Wks1.Range("A1:Z1").Find("WhatYouAreLookingFor",Wks1.Range("A1"),xlValues,xlWhole)

set rngSearch = Wks1.Range(“A1:Z1”)。Find(“WhatYouAreLookingFor”,Wks1.Range(“A1”),xlValues,xlWhole)

Then you can test if it contains the desired value or not by using

然后,您可以使用测试它是否包含所需的值

If Not rngSearch is nothing then

如果不是rngSearch则什么也没有

#2


0  

Set search = Wks1.Cells(i_col&"1")
If search.Value = "" Then

Too tired... Of course, "search" is a range object, that's why the code works with 'Set' and 'Search.Value'

太累了...当然,“搜索”是一个范围对象,这就是代码与'Set'和'Search.Value'一起使用的原因

I changed the code a bit

我稍微改了一下代码

Sorry for that

对不起

@Shrivallabha Redij - this might work, yeah

@Shrivallabha Redij - 这可能有效,是的

#1


0  

For this purpose, you can use FIND method like below without using a loop:

为此,您可以使用如下所示的FIND方法而不使用循环:

set rngSearch = Wks1.Range("A1:Z1").Find("WhatYouAreLookingFor",Wks1.Range("A1"),xlValues,xlWhole)

set rngSearch = Wks1.Range(“A1:Z1”)。Find(“WhatYouAreLookingFor”,Wks1.Range(“A1”),xlValues,xlWhole)

Then you can test if it contains the desired value or not by using

然后,您可以使用测试它是否包含所需的值

If Not rngSearch is nothing then

如果不是rngSearch则什么也没有

#2


0  

Set search = Wks1.Cells(i_col&"1")
If search.Value = "" Then

Too tired... Of course, "search" is a range object, that's why the code works with 'Set' and 'Search.Value'

太累了...当然,“搜索”是一个范围对象,这就是代码与'Set'和'Search.Value'一起使用的原因

I changed the code a bit

我稍微改了一下代码

Sorry for that

对不起

@Shrivallabha Redij - this might work, yeah

@Shrivallabha Redij - 这可能有效,是的