1

I have a syntax error in my if statement which I am confused about, seems like the compiler shouldn't require an = but I get an expected : = error on

if isempty(activecell) then activecell.offset(0,-1)

Range(zen).Select
oak = 1
Do
oak = oak + 1
If IsEmpty(ActiveCell) Then ActiveCell.Offset(0, -1)
Else: If IsEmpty(Selection.Offset(0, -1)) Then Copy Selection(activerow(E - M).Range)
Paste Selection.Offset(0, -1)
Loop Until oak = ruby

Here is the code in its entirety

Dim ws As Worksheet
Dim rng1 As Range
Dim ruby As Integer
Dim ruby2 As Integer
Set ws = Sheets("Belmont")
Set rng1 = ws.Columns("c").Find("*", ws.[c1], xlValues, , xlByRows, xlPrevious)
Dim zen As String
zen = rng1.Address(0, 0)
Range(zen).Select
ruby = ActiveCell.Row
ruby2 = ruby - 11
Dim stones() As Boolean
ReDim stones(1 To ruby)
Dim z As Integer
z = 1
Do
If IsEmpty(ActiveCell.Offset(2, 0)) Then
stones(z) = 0
Selection.Offset(-1, 0).Select
z = z + 1
Else
stones(z) = 1
Selection.Offset(-1, 0).Select
z = z + 1
End If
Loop Until z > ruby2
Range(zen).Select
oak = 1
Do
oak = oak + 1
If IsEmpty(ActiveCell) Then ActiveCell.Offset(0, -1)
Else: If IsEmpty(Selection.Offset(0, -1)) Then Copy Selection(activerow(E - M).Range)
Paste Selection.Offset(0, -1)
Loop Until oak = ruby
4

1 回答 1

2

ActiveCell.Offset(0, -1)是无效部分。您实际上需要对ActiveCell. 例如: ActiveCell.Offset(0, -1).Select将选择移动到该偏移量,或ActiveCell.Offset(0, -1) = "data value"将数据放入偏移单元格。

或者为该偏移单元格设置一个范围,例如:Set myRange = ActiveCell.Offset(0, -1)

此外,您应该将If-Then语法更改为对 VBA 更友好一点:

If IsEmpty(ActiveCell) Then
  ActiveCell.Offset(0, -1).Select
ElseIf IsEmpty(Selection.Offset(0, -1)) Then
    Dim row As Integer
    row = ActiveCell.row
    Range(Cells(row, 5), Cells(row, 13)).Select
    Selection.Copy
End If

并且activerow在 Excel 中无效,因此上述更改应该可以满足您的需求。

于 2013-08-19T18:51:57.520 回答