-1

I am trying to take a value from one cell, check if it matches a case, and then move down to the next cell to check it again. I can't get my code to work. I am very new to VBA so any help would be greatly appreciated!

Sub Grade_Convert()

Sheets(2).Select
grade = Range("A3").Select

Do

grade = ActiveCell.Value

 Select Case grade
    Case Is <= 49
        g = "F"
    Case Is <= 59
        g = "E"
    Case Is <= 69
        g = "D"
    Case Is <= 79
        g = "C"
    Case Is <= 89
        g = "B"
    Case Is <= 100
        g = "A"
 End Select
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = g
ActiveCell.Offset(-1, -1).Select
If (IsEmpty(ActiveCell)) = True Then Exit Do

Loop

End Sub```
hmoe
  • 1
  • 2
  • which line returns the error? Why are you using `.Select`? Why do you not declare any of your data types? What do you think you are doing with `grade = Range("A3").Select `? – Ron Rosenfeld Sep 29 '20 at 00:11
  • I'm using `.Select` because I was told to use it! I don't declare any data types because I don't know why it is necessary. I use `grade = Range("A3").Select` to set the variable grade to the first numerical grade, on cell A3. – hmoe Sep 29 '20 at 00:31
  • 1
    Suggestions: Read [How to avoid using Select in Excel VBA](https://stackoverflow.com/questions/10714251/how-to-avoid-using-select-in-excel-vba). Whoever told you to use it is wrong. You never use that first `grade =..` You subsequently set `grade =` to `ActiveCell` before you do anything else. Declaring data types is good practice so that VBA will only reserve the necessary memory required for the type. Requiring data type declaration in `Tools/Options` will place `Option Explicit` at the start of your module, and help in catching typos and other errors that can be hard to find otherwise. – Ron Rosenfeld Sep 29 '20 at 00:42

1 Answers1

-1

Found the issue. My second offset was offsetting to a cell that was not possible to access. The line is ActiveCell.Offset(-1, -1).Select One minus sign...

hmoe
  • 1
  • 2