excel vba将选中区域向下复制指定次数

excel vba将选中区域向下复制指定次数

1 需求

将选中区域向下复制4次

2 选中区域 A2:F6

执行VBA,会弹出对话框,输入数字4 (表示向下复制4次)

3 复制完成


VBA code

bash 复制代码
Sub CopySelection()
Dim numCopies As Integer
Dim selectedRange As Range
Dim i As Integer

' Prompt the user to enter a number
numCopies = Application.InputBox("Enter the number of times to copy the selection:", Type:=1)
' Check if a valid number is entered
If numCopies <= 0 Then
MsgBox "Please enter a valid positive number.", vbExclamation
Exit Sub
End If

' Store the selected range
Set selectedRange = Selection
' Copy the selection downwards the specified number of times
For i = 1 To numCopies
selectedRange.Offset(i * selectedRange.Rows.Count, 0).Value = selectedRange.Value
Next i
MsgBox "Selected range copied " & numCopies & " times.", vbInformation
End Sub
相关推荐
浪里个浪的10247 分钟前
C语言基础:条件语句与分支控制实例解析
c语言·开发语言
丶白泽10 分钟前
重修设计模式-结构型-装饰器模式
java·设计模式·装饰器模式
七月的和弦12 分钟前
交叉编译Python3.8
开发语言·python·交叉编译
三掌柜66612 分钟前
2024三掌柜赠书活动第二十九期:Python Web开发从入门到精通
开发语言·python
你不讲 wood18 分钟前
postcss 插件实现移动端适配
开发语言·前端·javascript·css·vue.js·ui·postcss
格林威23 分钟前
Baumer工业相机堡盟工业相机如何通过NEOAPI SDK使用超短曝光功能(曝光可设置1微秒)(Python)
开发语言·人工智能·python·数码相机·计算机视觉
AI原吾33 分钟前
探索SVG的奥秘:Python中的svgwrite库
android·开发语言·python·svgwrite
Tinalee-电商API接口呀43 分钟前
python爬虫爬取淘宝商品比价||淘宝商品详情API接口
大数据·开发语言·人工智能·爬虫·python·json
week_泽1 小时前
安装python,jupter notebook,anaconda换源
开发语言·python
星空下夜猫子1 小时前
JAVA 使用POI实现单元格行合并生成
java·开发语言