如何解决对象_worksheet的Excel VBA方法范围失败ERROR
Private Sub CommandButton1_Click()
Dim myFile As String
Dim wb As Workbook
Dim ws As Worksheet
curRow = 1
Dim maxRow As Integer
Dim copySuburb As String
myFile = Application.GetOpenFilename(,"Browse Workbook")
Set wb = Workbooks.Open(myFile)
wb.Activate
Set ws = wb.Sheets(1)
ws.Range("BB:AX,AV:AR,AQ:AL,AA:AK,X:W,U:T,N:O,L:B").Delete
ws.Rows(3).EntireRow.Delete
ws.Rows(2).EntireRow.Delete
ws.Rows(1).EntireRow.Delete
maxRow = ws.UsedRange.Rows.Count
ws.Rows(maxRow).EntireRow.Delete
ws.Rows(maxRow - 1).EntireRow.Delete
ws.Rows(maxRow - 2).EntireRow.Delete
maxRow = ws.UsedRange.EntireRow.Count
With ActiveWorkbook.ActiveSheet.Sort
.SortFields.Clear
.SortFields.Add Key:=Range("A1:A" & Rows.Count),Order:=xlAscending
.SortFields.Add Key:=Range("B1:B" & Rows.Count),Order:=xlAscending
.SetRange Range("A1:I" & Rows.Count)
.Header = xlNo
.Apply
End With
Do Until ws.Range("A" & curRow).Value = vbNullString
ws.Rows(curRow + 1).Insert shift:=xlShiftDown
ws.Range("C" & curRow).Value = ws.Range("D" & curRow - 1).Value
curRow = curRow + 2
Loop
End Sub
这是我的代码。我的问题是我在显示ws.Range("C" & curRow).Value = ws.Range("D" & curRow - 1).Value
我要做的就是将位于D列的单元格的值复制到C(不同的行)。我浏览了导致此错误的原因的互联网,我怀疑当前正在使用的工作表不是活动的?感谢您的帮助!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。