Question

Dim Brand As String, Status As String, CaseNumber As String, CaseSummary As String
    Worksheets("1st").Select
    Brand = Range("B25", Range("B25").End(xlDown))

I am trying to run a macros where when I click on a command button, it will insert all data from column B starting on row 25 and go all the way down until it hits the first blank cell. Problem is that it keeps telling me to debug and points to the third line of code in the code above. I thought I am doing this correctly but looks like I am not.

How can this line of code be fixed so that it looks through all data from column B up until it hits the first blank row in that column?

Was it helpful?

Solution 2

I think you have a couple of problems:

  1. You've defined Brand as a String, but later assign it to a range. You should probably redefine to Dim Brand As **Range**
  2. When you assign Brand to a range, you need to use the set keywork, like **set** Brand = Range...
  3. The Range definition seems to be missing a Range keyword: Range(Range("B25"), Range("B25").End(xlDown))

So, altogether it might look like this:

Dim Brand As Range, Status As String, CaseNumber As String, CaseSummary As String
    Worksheets("1st").Select
    set Brand = Range(Range("B25"), Range("B25").End(xlDown))

OTHER TIPS

By the look of it, you should either:

Dim Brand As Range

or

Dim Brand As Variant
Brand = Range("B25", Range("B25").End(xlDown)).Value

This will get you to compile.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top