在列B中的列A中自动填写相同的数字 [英] Autofill the same number from column A in column B

查看:145
本文介绍了在列B中的列A中自动填写相同的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要创建如下输出:

  Column A | Column B
1.    1          1
2.               1
3.    2          2
4.               2
5.               2

到目前为止,我写了以下代码:

So far, I have written the following code:

 Sub ItemNum()
 Dim rng As Range
 Dim i As Long
 Dim cell

 Set rng = Range("A1:A99")
     i = 1
     For Each cell In rng
        If (...) Then
           cell.Offset(0, 1).Value = i

        End If
     Next
End Sub

我已经在列A中获得了数字序列。我需要在列B中添加相同的值到列。

I have already obtained the number sequence in column A. I need to add the same value in column B down to the column.

我想知道如何添加到增量语句。

I would like to know how to add to increment statement.

谢谢

推荐答案

如果您想要做的是将A列的值放入每个单元格在列B中,直到您在列A中获得另一个值,则以下内容应该起作用:

If what you are wanting to do is place a value from column A into every cell in column B until you come to another value in Column A, then the following should work:

Sub ItemNum()
    Dim rng As Range
    Dim i As Variant
    Dim cell

    Set rng = Range("A1:A99")
    i = "Unknown"
    For Each cell In rng
        If Not IsEmpty(cell) Then
            i = cell.value
        End If
        cell.Offset(0, 1).Value = i
    Next
End Sub

这篇关于在列B中的列A中自动填写相同的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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