输出范围与输入范围相同

编程入门 行业动态 更新时间:2024-10-27 08:36:35
本文介绍了输出范围与输入范围相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一些使用VBA的历史,但是似乎找不到解决此问题的方法.我发现了一个迭代过程来选择一个单元格,执行一个过程,然后选择下一个单元格并再次执行该过程,直到NULL.将每个流程解决方案输出到下一列时遇到问题.这是我所拥有的:

I have some history working with VBA, but can't seem to find the solution to this problem. I found an iteration process to select a cell, do a process, and then select the next cell and do the process again, until NULL. I am having a problem outputting each of the processes solutions into the next column. Here is what I have:

Sub Name () Dim X As Integer Dim MyString as String Application.ScreenUpdating = False NumRows = Range("D2", Range("D2").End(xlDown)).Rows.Count Range("D2").Select For X = 1 To NumRows MyString = ActiveCell.Value MyString = Right(MyString, Len(MyString)-6) Range("I2 to I#").Value = MyString ActiveCell.Offset(1,0).Select Next X End Sub

Range("I2 to I#").Value = MyString 是我需要帮助的行.我需要它递增到I3,I4,I5等,直到达到NumRows计数.

Range("I2 to I#").Value = MyString is the line that I need help with. I need it to increment to I3, I4, I5, etc. until it reaches NumRows count.

推荐答案

使用单元格时,循环遍历它们的最佳方法是 Range中的每个单元格,因此请按照注释中的说明进行操作避免选择,这对您有帮助:

When working with Cells the best way to loop through them is For Each Cell in Range so taking this and as comments told you to avoid selecting, this should help you:

Option Explicit Sub Name() Dim C As Range, MyRange As Range Dim LastRow As Long Application.ScreenUpdating = False With ThisWorkbook.Sheets("MySheet") 'Change MySheet for your working sheet name LastRow = .Cells(.Rows.Count, "D").End(xlUp).Row 'last row on column D Set MyRange = .Range("D2:D" & LastRow) 'declare your working range For Each C In MyRange If Not C = vbNullString Then .Cells(C.Row, "I") = Right(C, Len(C) - 6) Next C End With Application.ScreenUpdating = True End Sub

更多推荐

输出范围与输入范围相同

本文发布于:2023-11-16 07:32:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1602256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!