[英]Excel Macro & VBA, Copy Cell Range to another sheet (transposed and based on another value)
I have tried to frankenstein a solution from different threads but I am very much a newbie to VBA and programming, so it has not been going too well... 我曾尝试从不同的线程开始弗兰肯斯坦的解决方案,但我是VBA和编程的新手,因此进展不太顺利...
Here's some basic info: 以下是一些基本信息:
Now, I am looking for 3 things (ideally in one compact solution) 现在,我正在寻找3件事(最好是在一个紧凑的解决方案中)
Have a Command Button that copies and transposes the most recent range (leftmost column) from Data Entry to Database. 有一个命令按钮,用于将最新范围(最左边的列)从数据输入复制并转置到数据库。 (This is done in the code below) (这在下面的代码中完成)
This should be done depending on a certain cell value on the data entry sheet (ideally that cell could stay part of the copied range, however this is not crucial) 应当根据数据输入表上的某个单元格值执行此操作(理想情况下,该单元格可以保留复制范围的一部分,但这并不重要)
Delete the original range from the data entry sheet. 从数据输入表中删除原始范围。
As I said I'm just starting to work with VBA so I am completely unsure how to go about this, I have attached what I gathered so far (excludes Nr.2 and feels very cumbersome overall). 正如我说过的那样,我刚开始使用VBA,所以我完全不确定该怎么做,我已经附加了到目前为止收集到的内容(不包括Nr.2,总体上感觉非常麻烦)。 Any help is very much appreciated! 很感谢任何形式的帮助!
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim xSheet As Worksheet
Set xSheet = ActiveSheet
If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
xSheet.Range("E6:E200").Copy
Worksheets("Sheet1").Range("E6:AZ6").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
End If
Application.ScreenUpdating = True
End Sub
Check this one. 检查这一。 It checks the value of E10. 它检查E10的值。 If it's "Y", then data is copied and deleted from original place. 如果为“ Y”,则从原始位置复制和删除数据。 Otherwise, it shows a message to the user. 否则,它会向用户显示一条消息。
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim xSheet As Worksheet
Set xSheet = ActiveSheet
If xSheet.Name <> "Definitions" And xSheet.Name <> "fx" And xSheet.Name <> "Needs" Then
If xSheet.Range("E10")="Y"
xSheet.Range("E6:E200").Copy
Worksheets("Sheet1").Range("E6:AZ6").PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
xSheet.Columns("E").Delete
Else
MsgBox("Data entry not ready!")
End If
End If
Application.ScreenUpdating = True
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.