View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
rick rick is offline
external usenet poster
 
Posts: 25
Default Better code needed

Hi,

Review the "cells method" (you should be able to find this
on the internet). Loop through the rows 2 to 4 with your
example (with a For Loop). This compresses your code.
After testing, change the lower and upper boundaries, as
you would like.

If you are still interested in the code I speak of, write
back and I'll take a look at it tomorrow and help you.

Rick


-----Original Message-----
I'm at a loss. Is there a way to write this code so it

is shorter and
works.... What I'm trying to do is if A2=F2 or G2 or if

A2 is between
F2 and G2 then B2=H2. I have a column of 100 cells

too. I've tried
vlook but is does the opposite of what I'm trying to do.
Thank you for all your help.

Public Sub TA()

If Range("A2").Value = Range("F2").Value Or _
Range("A2").Value = Range("G2").Value Then
Range("B2").Value = Range("H2").Value
Else
Range("B2").Value = ""
End If
If Range("A2").Value Range("F2").Value And _
Range("A2").Value < Range("G2").Value Then
Range("B2").Value = Range("H2").Value
Else
Range("B2").Value = ""
End If


If Range("A3").Value = Range("F2").Value Or _
Range("A3").Value = Range("G2").Value Then
Range("B3").Value = Range("H2").Value
Else
Range("B3").Value = ""
End If
If Range("A3").Value Range("F2").Value And _
Range("A3").Value < Range("G2").Value Then
Range("B3").Value = Range("H2").Value
Else
Range("B3").Value = ""
End If


If Range("A4").Value = Range("F2").Value Or _
Range("A4").Value = Range("G2").Value Then
Range("B4").Value = Range("H2").Value
Else
Range("B4").Value = ""
End If
If Range("A4").Value Range("F2").Value And _
Range("A4").Value < Range("G2").Value Then
Range("B4").Value = Range("H2").Value
Else
Range("B4").Value = ""
End If


End Sub


---
Message posted from http://www.ExcelForum.com/

.