Marcus Delatorre
Marcus Delatorre

Reputation: 13

Populate Column Using If Else Then Statement on another column in vba

Column C starts off with a column of numbers in text format. Column H is blank, and I want to populate each corresponding row with text based on the results from an If Elseif statement focused on column C.

I keep getting a error. "Application-defined or object-defined error". So I changed the formatting of those cells. I've also have had the issue where it doesn't step through the entire column. That's why I added the For Loop.

Thank you!!

[C:C].Select
With Selection
    .NumberFormat = "General"
    .Value = .Value
End With

For i = 1 To Rows.Count
Next i

If Cells(i, 3).Value = "40018" Then
    Cells(i, 8).String = "<0.100 W"
ElseIf Cells(i,3).Value="41020" Then
    Cells(i, 8).String = "asfsdfsfd"
End If

Upvotes: 0

Views: 36

Answers (1)

user9525052
user9525052

Reputation: 96

The error is because your code example tried to assign a value to the property ".String" (as in Cells(i, 8).String = "<0.100 W") which doesn't exist. Also, your If ElseIf statement should be inside the For loop to work correctly. Try the following code instead.

[C:C].Select
With Selection
    .NumberFormat = "General"
    .Value = .Value
End With

For i = 1 To Rows.Count
    If Cells(i, 3).Value = "40018" Then
        Cells(i, 8).Value = "<0.100 W"
    ElseIf Cells(i, 3).Value = "41020" Then
        Cells(i, 8).Value = "asfsdfsfd"
    End If
Next I

Upvotes: 1

Related Questions