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
相关推荐
咬_咬2 小时前
go语言学习(map)
开发语言·学习·golang·map
古城小栈2 小时前
rustup 命令工具,掌控 Rust 开发环境
开发语言·后端·rust
lly2024062 小时前
NumPy 高级索引
开发语言
菠萝地亚狂想曲2 小时前
Zephyr_01, environment
android·java·javascript
Arya_aa2 小时前
HTTP与Tmocat服务器与SpringMVC
java·spring boot
YDS8292 小时前
大营销平台 —— 抽奖规则决策树
java·springboot·ddd
XY_墨莲伊2 小时前
【编译原理】实验二:基于有穷自动机FA词法分析器设计与实现
c语言·开发语言·c++·python
广州灵眸科技有限公司2 小时前
瑞芯微(EASY EAI)RV1126B 网络摄像头方案
开发语言·网络·科技·嵌入式硬件·物联网
酿情师2 小时前
Shiro 反序列化漏洞原理(小白零基础详解)
java·web安全·网络安全
少许极端2 小时前
算法奇妙屋(四十五)-CCPC备战之旅-1
java·开发语言·算法