0

I am newbie in here in Stackoverflow and in the VBA Field. Actually I need some help with my code.

I have created a VBA(macro) and it seems there is missing with my code.

Scenario:

if column B3 has an answer(either: "FLAT" or "PER") should be applicable to all column which is same in Column A3

for example

if A3 until A500 then B3 until B500 has also an answer (either: "FLAT" or "PER").

Sub exe()

    Dim number As Integer, result As String

    number = Range(“a1”).Value

    If number <= 1 Then

    result = “Flat”

    Else: result = “Per”

    End If

    Range(“b1”).Value = result

End Sub
  • 1
    Is your question about how to [find the last row](https://stackoverflow.com/questions/11169445/error-in-finding-last-used-cell-in-excel-with-vba) in column E? – BigBen Mar 06 '20 at 13:40
  • Your code only looks at Cell `F3` and `IU3` , not the whole column. Is that what you are trying to do? – Daghan Mar 06 '20 at 13:48
  • Hello Big Ben Yes it is and the other problem is I don't know how to put or look for the last row instead looking into 1 cells it should be look for the whole column. – christian estrella Mar 06 '20 at 13:52
  • What result I want is if the column before the F and thats column E should have fill it example if the column E3:E500 has data it should have also fill it the column F3:F500. – christian estrella Mar 06 '20 at 13:58
  • A small sample of data and expected results might be easier to understand. Your code isn't touching the column E at all, so what is to be done with it? – Christofer Weber Mar 06 '20 at 14:47
  • I have edit it sorry for the confusion – christian estrella Mar 06 '20 at 15:03
  • @ChristoferWeber can you help me about this? I have edit the description and sorry for the confusion I just do really need it. – christian estrella Mar 06 '20 at 15:20
  • 1
    I don't understand your question. Suggest you read the HELP topics for [How do I Ask a Good Question](http://stackoverflow.com/help/how-to-ask), and also [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). Then edit your question to provide more information. – Ron Rosenfeld Mar 06 '20 at 16:02

1 Answers1

0

Are you look for something like this:

Sub exe()

    Dim LastRow As Long, i As Long

    With ThisWorkbook.Worksheets("Sheet1")

        LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row

        For i = 1 To LastRow

            If .Range("A" & i).Value = 0.5 Then
                .Range("B" & i).Value = "FLAT"
            ElseIf .Range("A" & i).Value = 2 Then
                .Range("B" & i).Value = "PER"
            End If

        Next i

    End With

End Sub
Error 1004
  • 7,877
  • 3
  • 23
  • 46