ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   If statement in VBA (https://www.excelbanter.com/excel-discussion-misc-queries/1093-if-statement-vba.html)

Jeff

If statement in VBA
 
Hello,

I need help designing a VBA Macro to execute the following:

IF (A2=A1,0,1)
I need to execute this VBA macro from 1 to 300.
Thanks,


Ron de Bruin

Try this for the active sheet
It will use the B column to display the 0 or 1

Sub test()
Dim a As Long
For a = 2 To 300
If Cells(a, 1).Value = Cells(a - 1, 1).Value Then
Cells(a, 2).Value = 0
Else
Cells(a, 2).Value = 1
End If
Next a
End Sub



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Jeff" wrote in message ...
Hello,

I need help designing a VBA Macro to execute the following:

IF (A2=A1,0,1)
I need to execute this VBA macro from 1 to 300.
Thanks,





All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com