嗨,我是这个论坛的新手。
我想将范围a1:a10
从sheet 1
复制到sheet 2
的单元格,从a10
开始,增加10个单元格。即:
sheet1:a1
上的sheet2:a10
的内容; sheet1:a2
上的sheet2:a20
的内容; sheet1:a3
上的sheet2:a30
的内容; 我知道简单范围复制和粘贴的代码如下
Sub Copy(
Dim CopyFrom As Range
Set CopyFrom = Sheets("Sheet1").Range("A2 : A10")
Sheets("Sheet2").Range("A1").Resize(CopyFrom.Rows.Count).Value = CopyFrom.Value
End Sub
请编辑上面的代码以帮助满足我的需求。
a1
包含10且单元格a2
包含50,则应隐藏第10至50行。我可以通过将一个值设置为固定并从单元格调用一个值而不是两个来完成上述操作。
Sub AUTOHIDE_ROWS_307()
'
Application.ScreenUpdating = False
Sheets("sheet1").Select
Dim Cval As Variant
Dim Rng1 As Range
Cval = ActiveSheet.Range("a1").Value
Set Rng1 = ActiveSheet.Range("A50:N" & Cval)
Rng1.Activate
Selection.EntireRow.Hidden = True
Application.ScreenUpdating = True
End Sub
请通过上面的编辑来帮助满足我的需求。
提前致谢。
答案 0 :(得分:0)
我知道这不是本论坛的目的,但你在这里迷失了,并且会给你一些你可以作为起点的东西。
Sub doThatCopy()
'Create your variables
Dim myFormerSheetRow, myDestinationSheetRow, myFormerColumn, myDestinationColumn As Integer
Dim myFormerSheetName, myDestinationSheetName As String
'Setting the variables first values
myFormerColumn = 1 ' 1 = A, 2 = B...
myDestinationColumn = 3 '3 = C
myFormerSheetRow = 0 ' This row, doesn't exists, but we'll increment it before first use
myDestinationSheetRow = 1
myFormerSheetName = "Sheet1"
myDestinationSheetName = "Sheet2"
For i = 1 To 10
'You could use "myFormerSheetRow = i" instead of the row below, but I'll leave it this way to be more understandable for you
myFormerSheetRow = myFormerSheetRow + 1
myDestinationSheetRow = myFormerSheetRow * 10
ActiveWorkbook.Worksheets(myDestinationSheetName).Cells(myDestinationSheetRow, myDestinationColumn).Value = ActiveWorkbook.Worksheets(myFormerSheetName).Cells(myFormerSheetRow, myFormerColumn).Value
Next i
MsgBox ("Success!")
End Sub
答案 1 :(得分:0)
1
pkill
2
Dim I as Integer
For I = 1 To 10
Sheets("Sheet2").Cells(1, I * 10) = Sheets("Sheet1").Cells(1, I)
Next