Excel精英培训网

 找回密码
 注册
数据透视表40+个常用小技巧,让你一次学会!
查看: 2078|回复: 7

[已解决]求助!如何将A列单元格内容引用到G列单元格

[复制链接]
发表于 2012-8-16 14:53 | 显示全部楼层 |阅读模式
问题见附件 Book12.zip (8.01 KB, 下载次数: 24)
发表于 2012-8-16 15:04 | 显示全部楼层
  1. Sub abc()
  2. Dim arr, i
  3. arr = Range("a1").CurrentRegion
  4. For i = 1 To [G65536].End(3).Row
  5. For j = 1 To UBound(arr)
  6. If Cells(i, "g") = arr(j, 1) Then
  7. Cells(i, "g").Offset(, 1) = arr(j, 2)
  8. Cells(i, "g").Offset(, 2) = arr(j, 3)
  9. Cells(i, "g").Offset(, 3) = arr(j, 4)
  10. End If
  11. Next j
  12. Next i
  13. End Sub
复制代码
这样可以么?
回复

使用道具 举报

 楼主| 发表于 2012-8-16 15:09 | 显示全部楼层
老师,可能是我问题没有说明白,在引用了G列单元格123后面又继续引用。
回复

使用道具 举报

发表于 2012-8-16 15:15 | 显示全部楼层
xxjjdd0000 发表于 2012-8-16 15:09
老师,可能是我问题没有说明白,在引用了G列单元格123后面又继续引用。
  1. Sub abc()
  2. Dim arr, i, j, icolumn
  3. arr = Range("a1").CurrentRegion
  4. icolumn = Range("g1").End(xlToRight).Column
  5. For i = 1 To [G65536].End(3).Row
  6. For j = 1 To UBound(arr)
  7. If Cells(i, "g") = arr(j, 1) Then
  8. Cells(i, icolumn).Offset(, 1) = arr(j, 2)
  9. Cells(i, icolumn).Offset(, 2) = arr(j, 3)
  10. Cells(i, icolumn).Offset(, 3) = arr(j, 4)
  11. End If
  12. Next j
  13. Next i
  14. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-8-16 15:20 | 显示全部楼层
老师,出现错误,就是应用程序错误或定义错误

Book12.zip

7.7 KB, 下载次数: 7

回复

使用道具 举报

 楼主| 发表于 2012-8-16 15:21 | 显示全部楼层
就是当把G列右边清除后,出现上述错误的。
回复

使用道具 举报

发表于 2012-8-16 15:26 | 显示全部楼层    本楼为最佳答案   
xxjjdd0000 发表于 2012-8-16 15:20
老师,出现错误,就是应用程序错误或定义错误
  1. Sub abc()
  2. Dim arr, i, j, icolumn
  3. arr = Range("a1").CurrentRegion
  4. icolumn = Cells(1, 256).End(xlToLeft).Column
  5. For i = 1 To [G65536].End(3).Row
  6. For j = 1 To UBound(arr)
  7. If Cells(i, "g") = arr(j, 1) Then
  8. Cells(i, icolumn).Offset(, 1) = arr(j, 2)
  9. Cells(i, icolumn).Offset(, 2) = arr(j, 3)
  10. Cells(i, icolumn).Offset(, 3) = arr(j, 4)
  11. End If
  12. Next j
  13. Next i
  14. End Sub
复制代码
回复

使用道具 举报

 楼主| 发表于 2012-8-16 15:28 | 显示全部楼层
谢谢,已完美运行。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|Archiver|Excel精英培训 ( 豫ICP备11015029号 )

GMT+8, 2024-5-5 17:58 , Processed in 0.244389 second(s), 11 queries , Gzip On, Yac On.

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表