0

I am trying to concatenate cells as per below VBA script but it gives me run-time error '91' - Object variable or With Block variable not set. I guess that's smth to do with variable "x"? Can anyone help please?

Sub Macro1()

Dim Cells As Range
Dim x As Integer

x = 2

Do While Cells(x, 1) <> ""
Cells(x, 2) = Cells(x, 2) & Cells(x, 3) & Cells(x, 4)
Cells(x, 2) = ""
x = x + 1
Loop
Columns("B:B").EntireColumn.AutoFit

End Sub
3
  • 2
    Get rid of Dim Cells As Range. Commented Dec 3, 2020 at 14:49
  • Hi BigBen thanks you are always willing to help! That helped with error! Much appreciated! This macro should concatenate values from columns B,C,D, save them in column B and then delete the columns C & D, but it's only clears the contents starting from B2 and down the column :( do you have any idea on that? Commented Dec 3, 2020 at 15:02
  • Cells(x, 2) = "" - change that to Range("C" & x & ":D" & x).ClearContents. Commented Dec 3, 2020 at 15:06

1 Answer 1

1

Putting comments into an answer:

  • Remove Dim Cells As Range, which is shadowing Cells from the Excel Object Model and causing the RTE 91.
  • Change Cells(x, 2) = " to Range("C" & x & ":D" & x).ClearContents.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.