根据相邻单元格的值从参考列进行复制 [英] Copying from reference column based on neighboring cell value

查看:34
本文介绍了根据相邻单元格的值从参考列进行复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试创建宏或公式来执行以下操作,但是由于Ive陷入困境-我将向您寻求帮助.

I have been trying to create a macro or a formula in order to do the following, but since Ive becomes stumped- I'm going to reach out to you guys for help.

我要实现的宏是能够基于对相邻单元的引用从活动单元向下复制的宏.这个相邻的单元格,我们可以称其为参考单元格.

What I would like to achieve is the macro to be able to copy from the active cell downward based on reference to a neighbouring cell. This neighbouring cell, we can call it the reference cell.

只要参考列不为空,则应从活动单元向下复制该宏,并且该宏还应足够聪明,以便在遇到空白参考单元时向下跳转并转到下一个参考单元,直到最后一个填充的单元格.

This macro is supposed to copy from the active cell downward as long as the reference column is not empty and the macro is also to be smart enough to skip downward when a blank reference cell is encountered and go onto the next reference cell until the last filled cell.

是否可以做类似的事情?

Is it possible to do something like that?

在此先感谢您的帮助!

推荐答案

这里是供您使用的示例,它假定Neighbor列在右上方:

Here is a sample for you to work from, it assumes the Neighbor column is one over to the right:

Sub Sample()
Dim rngStart As Range
Dim lngLastRow As Long
Dim lngDiff As Long

Set rngStart = ActiveCell
lngLastRow = Cells(Rows.Count, rngStart.Offset(0, 1).Column).End(xlUp).Row

lngDiff = lngLastRow - rngStart.Row + 1

Set rngStart = rngStart.Resize(lngDiff)
rngStart.Select
End Sub

这篇关于根据相邻单元格的值从参考列进行复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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