PC Review


Reply
Thread Tools Rate Thread

Adding a line in a row

 
 
CAM
Guest
Posts: n/a
 
      5th Dec 2008
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 With Quote
 
 
 
 
Rick Rothstein
Guest
Posts: n/a
 
      5th Dec 2008
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" <(E-Mail Removed)> wrote in message
news:6D183A99-6EEF-40A2-9B94-(E-Mail Removed)...
> 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 With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      5th Dec 2008
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" <(E-Mail Removed)> wrote in message
news:OxW%(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:6D183A99-6EEF-40A2-9B94-(E-Mail Removed)...
>> 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 With Quote
 
Don Guillett
Guest
Posts: n/a
 
      5th Dec 2008
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
(E-Mail Removed)
"CAM" <(E-Mail Removed)> wrote in message
news:6D183A99-6EEF-40A2-9B94-(E-Mail Removed)...
> 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 With Quote
 
CAM
Guest
Posts: n/a
 
      5th Dec 2008
Rick I changed from ("Sheet3") to ("Sheet1"). Thanks for you help. I
really appreciate your skills.

Regards,


"Rick Rothstein" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:OxW%(E-Mail Removed)...
>> 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" <(E-Mail Removed)> wrote in message
>> news:6D183A99-6EEF-40A2-9B94-(E-Mail Removed)...
>>> 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 With Quote
 
CAM
Guest
Posts: n/a
 
      5th Dec 2008
Thanks Don, I appreciate the tip.

Regards,

"Don Guillett" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
> (E-Mail Removed)
> "CAM" <(E-Mail Removed)> wrote in message
> news:6D183A99-6EEF-40A2-9B94-(E-Mail Removed)...
>> 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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem adding vertical marker line to line chart lbb Microsoft Excel Charting 6 9th Jan 2009 09:02 AM
Adding a line to the line/column chart? Steven Microsoft Excel Charting 2 12th Feb 2007 09:46 PM
Chart Type - Line Column adding a 2nd line ljmacjunk@yahoo.com Microsoft Excel Charting 1 24th Oct 2006 04:17 PM
Line numbering started adding an {1} to the left of the line numbe =?Utf-8?B?bWljaA==?= Microsoft Word Document Management 1 4th Aug 2005 03:47 PM
Adding a blank line after each line of data Pablo Microsoft Excel Misc 3 21st May 2004 06:03 AM


Features
 

Advertising
 

Newsgroups
 


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