如果单元格不为空,则在其他选项卡中返回列"a"中的值 [英] If a cell is not null return the value in column 'a' in a different tab

查看:143
本文介绍了如果单元格不为空,则在其他选项卡中返回列"a"中的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个工作表上列出了一系列产品,您可以在其中选择所需的每种产品,但并不是每个产品都具有价值.在一个单独的工作表中,我希望它仅套用已选择金额的产品.请咨询.

I have a list of products listed on one worksheet where you can select how many of each you want, but not every product will have a value. In a separate worksheet I want it to only pull over the product that have a amount selected. Please Advice.

第一个工作表:

A        B

a        3

c       45

d   

e   

f       10

所需的第二个工作表:

A       B

b       3

c      45

f      10

推荐答案

您可以通过简单的VBA子例程获得所需的内容:

You can get what you want with a simple VBA subroutine:

Sub notNull()
    Dim count As Integer
    count = Application.WorksheetFunction.CountA(Range("A:A"))
    Dim i As Integer
    i = 1
    Dim rowCount As Integer
    rowCount = 1
    Do While i <= count
        If (Range("B" & i) <> "") Then
            Worksheets("Sheet2").Range("A" & rowCount) = Range("A" & i)
            Worksheets("Sheet2").Range("B" & rowCount) = Range("B" & i)
            rowCount = rowCount + 1
        End If
        i = i + 1
    Loop
End Sub

它的作用是遍历A列中包含数据的所有行,检查B列中的关联值是否等于",否则,将两个值都复制到另一张纸上.希望这会有所帮助!

What it does is it goes through all of the rows with data in column A, checks if the associated value in column B is equal to "", and if it isn't, it copies over both values onto another sheet. Hope this helps!

这篇关于如果单元格不为空,则在其他选项卡中返回列"a"中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆