View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.programming
John John is offline
external usenet poster
 
Posts: 2,069
Default Excel macro programming question


Anne,
here is another approach using find. Procedure should divide values in Col E
by two as required but also, it will ensure that this is done once only by
making 42 value bold. When run again, bold values are ignored.

Hope helpful

Sub DevideIf42()
Dim c As Range
Dim FirstAddress As String
With Worksheets(1).Range("B:B")

Set c = .Find(42, LookIn:=xlValues)

If Not c Is Nothing Then

FirstAddress = c.Address

Do
If c.Font.Bold = False Then

c.Offset(0, 3) = c.Offset(0, 3).Value / 2

c.Font.Bold = True

End If

Set c = .FindNext(c)

If c Is Nothing Then Exit Do

Loop Until c.Address = FirstAddress

End If

End With

End Sub

--
jb


"Anne" wrote:

Hello!
I have a worksheet with cols. A, B, C, D, and E. I want to do an if-then
statement in a macro that says, If B has "42" in it (no matter how long the
worksheet is, because they will vary widely), then divide the amount paid (E)
by 2.

B1 will always have Fund as its name; E1 will always have Amount Paid. As
mentioned, the size of the worksheet may vary a lot, so I was thinking I'd
use a range, but I'm not sure how to.

Example:
Columns
A B C D E
Row
1 Dept. Fund Vendor Desc Amount Paid

2 100 42 X Y 100.00

3 100 43 Z A 100.00

4 101 43 M G 100.00

After the code ran, E2 would be 50.00.

I'd like to put this in as a module, to make a little macro button for it.
(I know how to do that.) Any help would be appreciated. --Anne