Thread: simplify code
View Single Post
  #1   Report Post  
matt
 
Posts: n/a
Default simplify code

Hi,

I'm pretty new to writing code, so I wanted to ask for some advice. I've got
a code which checks to see if cells in two columns are equal, and if they are
not, it inserts blank cells in three columns. It works, but it is pretty
slow, as I have written three separate IF statements for inserting blank
cells. Is there any way that I can condense this into one IF statement? the
code I am using so far is:

LastRow = ActiveSheet.Cells(Rows.Count, "b").End(xlUp).Row
Range("E1").Select
For j=1 To LastRow
If Range("b" & j) < Range("a" & j) Then Range("b" & j).Select
Selection.Insert Shift:=xlDown
If Range("b" & j) < Range("a" & j) Then Range("c" & j).Select
Selection.Insert Shift:=xlDown
If Range("b" & j) < Range("a" & j) Then Range("d" & j).Select
Selection.Insert Shift:=xlDown
Range("e" & j).Select
Next j

Any help would be greatly appreciated.