Formatting in VBA

dunk

New Member
Joined
Feb 19, 2002
Messages
30
In an excel spreadsheet I'm looking to find a way to search the entire spreadsheet, find the "Dept Total" cells, go to the cell to the right of it(this contains a currency value)and put a top border line above this cells contents. This will make a visible split between lots of Dept Totals.

Any help would be very welcome
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Hi Dunk

here is one way to do this;

Sub finder()
Dim SearchString As String
Dim Sh, F, Location As String, Flag, Found1st

SearchString = "Dept Total"
Set Sh = Sheets.Application

For Each Sh In Application.Sheets
Flag = 0
With Sh.Range("A1:IV65536")
Do
Set F = .Find(SearchString, lookat:=xlWhole, after:=ActiveCell, LookIn:=xlValues)
If Not F Is Nothing Then
If Flag = 0 Then Found1st = F.Offset(0, 1).Address(external:=True)
Location = F.Address
Sh.Select
Range(Location).Offset(0, 1).Select
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlMedium
.ColorIndex = xlAutomatic
End With
Flag = Flag + 1
End If
Loop Until Found1st = ActiveCell.Address(external:=True) And Flag > 2 Or F Is Nothing
End With
Next Sh

End Sub


HTH

Ivan
 
Upvote 0
I'm now looking to modify the above code so that it formats the next nine cells in the same row, and not just the next cell.

Any help appreciated

dunk
 
Upvote 0

Forum statistics

Threads
1,214,515
Messages
6,119,970
Members
448,933
Latest member
Bluedbw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top