Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 65
Default Adding a line in a row

Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column A.
Now I want the border on top of the "Total" starting from column A - H. The
worksheet is large and will have many "Total" in it. How do I code that?
Any tips will be appreciated. Thank you in advance.

Regards,

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Adding a line in a row

Try this macro...

Sub BorderOnTotal()
Dim R As Range
Dim FirstAddress As String
With Worksheets("Sheet3").Columns(1)
Set R = .Find("Total")
If Not R Is Nothing Then
FirstAddress = R.Address
Do
R.Borders(xlEdgeTop).LineStyle = xlContinuous
Set R = .FindNext(R)
Loop While Not R Is Nothing And R.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"CAM" wrote in message
...
Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column
A. Now I want the border on top of the "Total" starting from column A - H.
The worksheet is large and will have many "Total" in it. How do I code
that? Any tips will be appreciated. Thank you in advance.

Regards,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default Adding a line in a row

Whoops! I forgot the A to H part. Try this macro instead...

Sub BorderOnTotal()
Dim R As Range
Dim FirstAddress As String
With Worksheets("Sheet3").Columns(1)
Set R = .Find("Total")
If Not R Is Nothing Then
FirstAddress = R.Address
Do
R.Resize(1, 8).Borders(xlEdgeTop).LineStyle = xlContinuous
Set R = .FindNext(R)
Loop While Not R Is Nothing And R.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Try this macro...

Sub BorderOnTotal()
Dim R As Range
Dim FirstAddress As String
With Worksheets("Sheet3").Columns(1)
Set R = .Find("Total")
If Not R Is Nothing Then
FirstAddress = R.Address
Do
R.Borders(xlEdgeTop).LineStyle = xlContinuous
Set R = .FindNext(R)
Loop While Not R Is Nothing And R.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"CAM" wrote in message
...
Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column
A. Now I want the border on top of the "Total" starting from column A -
H. The worksheet is large and will have many "Total" in it. How do I
code that? Any tips will be appreciated. Thank you in advance.

Regards,



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Adding a line in a row

Try this
Sub underlineabovetotal()
With Worksheets("sheet3").Range("a1:a500")
Set c = .Find("Total", After:=Range("a1"), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext,MatchCase:=False)

If Not c Is Nothing Then
firstAddress = c.Address
Do
With .cells(c.Row - 1, "a").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
End With
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"CAM" wrote in message
...
Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column
A. Now I want the border on top of the "Total" starting from column A - H.
The worksheet is large and will have many "Total" in it. How do I code
that? Any tips will be appreciated. Thank you in advance.

Regards,


  #5   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 65
Default Adding a line in a row

Rick I changed from ("Sheet3") to ("Sheet1"). Thanks for you help. I
really appreciate your skills.

Regards,


"Rick Rothstein" wrote in message
...
Whoops! I forgot the A to H part. Try this macro instead...

Sub BorderOnTotal()
Dim R As Range
Dim FirstAddress As String
With Worksheets("Sheet3").Columns(1)
Set R = .Find("Total")
If Not R Is Nothing Then
FirstAddress = R.Address
Do
R.Resize(1, 8).Borders(xlEdgeTop).LineStyle = xlContinuous
Set R = .FindNext(R)
Loop While Not R Is Nothing And R.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"Rick Rothstein" wrote in message
...
Try this macro...

Sub BorderOnTotal()
Dim R As Range
Dim FirstAddress As String
With Worksheets("Sheet3").Columns(1)
Set R = .Find("Total")
If Not R Is Nothing Then
FirstAddress = R.Address
Do
R.Borders(xlEdgeTop).LineStyle = xlContinuous
Set R = .FindNext(R)
Loop While Not R Is Nothing And R.Address < FirstAddress
End If
End With
End Sub

--
Rick (MVP - Excel)


"CAM" wrote in message
...
Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column
A. Now I want the border on top of the "Total" starting from column A -
H. The worksheet is large and will have many "Total" in it. How do I
code that? Any tips will be appreciated. Thank you in advance.

Regards,






  #6   Report Post  
Posted to microsoft.public.excel.programming
CAM CAM is offline
external usenet poster
 
Posts: 65
Default Adding a line in a row

Thanks Don, I appreciate the tip.

Regards,

"Don Guillett" wrote in message
...
Try this
Sub underlineabovetotal()
With Worksheets("sheet3").Range("a1:a500")
Set c = .Find("Total", After:=Range("a1"), LookIn:=xlValues, _
LookAt:=xlWhole, SearchOrder:=xlByRows, _
SearchDirection:=xlNext,MatchCase:=False)

If Not c Is Nothing Then
firstAddress = c.Address
Do
With .cells(c.Row - 1, "a").Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThick
End With
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address < firstAddress
End If
End With

End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"CAM" wrote in message
...
Hello,


I would like to add a border using vba coding to a worksheet this should
only applies when there is a cell containing the text "Total" in column
A. Now I want the border on top of the "Total" starting from column A -
H. The worksheet is large and will have many "Total" in it. How do I
code that? Any tips will be appreciated. Thank you in advance.

Regards,



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding vertical marker line to line chart lbb Charts and Charting in Excel 6 January 9th 09 09:02 AM
Adding a Second and Third Line to an Existing Stacked Bar/Line Cha billbrandi Charts and Charting in Excel 3 September 12th 08 03:27 PM
Adding a line to the line/column chart? Steven Charts and Charting in Excel 2 February 12th 07 09:46 PM
Chart Type - Line Column adding a 2nd line [email protected] Charts and Charting in Excel 1 October 24th 06 04:17 PM
Adding a new Line cakonopka[_15_] Excel Programming 2 February 4th 04 05:47 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"