在最后一行下方添加行 [英] Add rows below last row

查看:247
本文介绍了在最后一行下方添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在设计一个数据提交电子表格,其中包含12行数据(当前为22至33行)。第34至42行充满文字。如果要使用分配给按钮的宏输入12个以上的数据集,且格式与第33行相同,我想在第33行下方添加新行(第34行)。这很容易,但是如果我需要在第34行下面再增加一个新行(现在是第35行),那么我需要一个灵活的代码来做到这一点;我的总是在行33下方而不是数据条目集的最后一行下方添加新行。我该怎么做呢?我对VBA还是很陌生...

I'm designing a data submission spreadsheet with 12 rows of data (currently row 22 to 33). Rows 34 to 42 are filled with text. I'd like to add a new row (row 34) below row 33 if more than 12 data sets are to be entered, with the same format as row 33, using a macro assigned to a button. That's easy, but if I need another new row (now row 35) below row 34, I need a code is flexible to do that; mine always adds the new line below row 33, not below the last row of the data entry set. How do I do this? I'm quite new to VBA...

谢谢,

Andy

推荐答案

我认为Don's答案不起作用,因为您声明在第34至42行中有文本。

I don't think Don's answer will work, because you state you have text in rows 34 to 42.

如果第34行中的单元格的文本值不变,则可以搜索该单元格并在其上方插入一行。

If the text value of the cell in row 34 doesn't change, you can search for that cell and insert a row above it.

Dim someText As String
someText = "Text value of row 34"

Dim currentRange As Range
Set currentRange = Selection

With Range("A:A").find(someText) 'change the range if needed
    .EntireRow.Insert
    .Offset(-2).EntireRow.Copy
    .Offset(-1).EntireRow.PasteSpecial xlPasteFormats 'change the paste type as needed
End With
Application.CutCopyMode = False 'get rid of the marching ants
currentRange.Select 'select whatever was selected before
'alternative: Range("A1").Select

这篇关于在最后一行下方添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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