PC Review


Reply
 
 
Seeker
Guest
Posts: n/a
 
      29th May 2009
Please help to debug following code which was collected and restructured
several codes from the discussion groups. I intended to add a thick black
bottom border to upper row if two rows contain different data, and then add a
blank row in between, now correct number of rows has formatted with a thick
black bottom border but all placed start from the last row up.

Expected result
AAAA
AAAA
AAAA 'thick bottom border
'Empty row in between
BBBB
BBBB 'thick bottom border
'Empty row in between
CCCC 'thick bottom border

Dim LastRow As Long
Dim lngRow As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:X" & LastRow).Select

For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then

Selection.Borders(xlEdgeTop).LineStyle = xlDot
Selection.Borders(xlEdgeTop).Weight = xlThin
Selection.Borders(xlEdgeTop).ColorIndex = 15

Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
Selection.Borders(xlEdgeBottom).Weight = xlThick
Selection.Borders(xlEdgeBottom).ColorIndex = 1

Selection.Borders(xlEdgeRight).LineStyle = xlDot
Selection.Borders(xlEdgeRight).Weight = xlThin
Selection.Borders(xlEdgeRight).ColorIndex = 15

Selection.Borders(xlInsideVertical).LineStyle = xlDot
Selection.Borders(xlInsideVertical).Weight = xlThin
Selection.Borders(xlInsideVertical).ColorIndex = 15

Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
Selection.Borders(xlInsideHorizontal).Weight = xlThin
Selection.Borders(xlInsideHorizontal).ColorIndex = 15

Rows(lngRow).EntireRow.Insert
Else
Selection.Borders.LineStyle = xlDot
Selection.Borders.Weight = xlThin
Selection.Borders.ColorIndex = 15
End If
Rgds
 
Reply With Quote
 
 
 
 
Jim Thomlinson
Guest
Posts: n/a
 
      29th May 2009
Try this...

Dim LastRow As Long
Dim lngRow As Long

LastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("A1:X" & LastRow).Select

For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
with range(cells(lngrow, "A"), Cells(lngrow, "X"))
.Borders(xlEdgeTop).LineStyle = xlDot
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeTop).ColorIndex = 15

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeBottom).ColorIndex = 1

.Borders(xlEdgeRight).LineStyle = xlDot
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlEdgeRight).ColorIndex = 15

.Borders(xlInsideVertical).LineStyle = xlDot
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideVertical).ColorIndex = 15

.Borders(xlInsideHorizontal).LineStyle = xlDot
.Borders(xlInsideHorizontal).Weight = xlThin
.Borders(xlInsideHorizontal).ColorIndex = 15

Rows(lngRow).EntireRow.Insert
Else
.Borders.LineStyle = xlDot
.Borders.Weight = xlThin
.Borders.ColorIndex = 15
end with
End If

--
HTH...

Jim Thomlinson


"Seeker" wrote:

> Please help to debug following code which was collected and restructured
> several codes from the discussion groups. I intended to add a thick black
> bottom border to upper row if two rows contain different data, and then add a
> blank row in between, now correct number of rows has formatted with a thick
> black bottom border but all placed start from the last row up.
>
> Expected result
> AAAA
> AAAA
> AAAA 'thick bottom border
> 'Empty row in between
> BBBB
> BBBB 'thick bottom border
> 'Empty row in between
> CCCC 'thick bottom border
>
> Dim LastRow As Long
> Dim lngRow As Long
>
> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
> Range("A1:X" & LastRow).Select
>
> For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
> If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
>
> Selection.Borders(xlEdgeTop).LineStyle = xlDot
> Selection.Borders(xlEdgeTop).Weight = xlThin
> Selection.Borders(xlEdgeTop).ColorIndex = 15
>
> Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
> Selection.Borders(xlEdgeBottom).Weight = xlThick
> Selection.Borders(xlEdgeBottom).ColorIndex = 1
>
> Selection.Borders(xlEdgeRight).LineStyle = xlDot
> Selection.Borders(xlEdgeRight).Weight = xlThin
> Selection.Borders(xlEdgeRight).ColorIndex = 15
>
> Selection.Borders(xlInsideVertical).LineStyle = xlDot
> Selection.Borders(xlInsideVertical).Weight = xlThin
> Selection.Borders(xlInsideVertical).ColorIndex = 15
>
> Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
> Selection.Borders(xlInsideHorizontal).Weight = xlThin
> Selection.Borders(xlInsideHorizontal).ColorIndex = 15
>
> Rows(lngRow).EntireRow.Insert
> Else
> Selection.Borders.LineStyle = xlDot
> Selection.Borders.Weight = xlThin
> Selection.Borders.ColorIndex = 15
> End If
> Rgds

 
Reply With Quote
 
Seeker
Guest
Posts: n/a
 
      30th May 2009
Hi Jim,
Thanks for your reply, when I test your code, the compiler said "Else
without If"?
Rgds

"Jim Thomlinson" wrote:

> Try this...
>
> Dim LastRow As Long
> Dim lngRow As Long
>
> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
> Range("A1:X" & LastRow).Select
>
> For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
> If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
> with range(cells(lngrow, "A"), Cells(lngrow, "X"))
> .Borders(xlEdgeTop).LineStyle = xlDot
> .Borders(xlEdgeTop).Weight = xlThin
> .Borders(xlEdgeTop).ColorIndex = 15
>
> .Borders(xlEdgeBottom).LineStyle = xlContinuous
> .Borders(xlEdgeBottom).Weight = xlThick
> .Borders(xlEdgeBottom).ColorIndex = 1
>
> .Borders(xlEdgeRight).LineStyle = xlDot
> .Borders(xlEdgeRight).Weight = xlThin
> .Borders(xlEdgeRight).ColorIndex = 15
>
> .Borders(xlInsideVertical).LineStyle = xlDot
> .Borders(xlInsideVertical).Weight = xlThin
> .Borders(xlInsideVertical).ColorIndex = 15
>
> .Borders(xlInsideHorizontal).LineStyle = xlDot
> .Borders(xlInsideHorizontal).Weight = xlThin
> .Borders(xlInsideHorizontal).ColorIndex = 15
>
> Rows(lngRow).EntireRow.Insert
> Else
> .Borders.LineStyle = xlDot
> .Borders.Weight = xlThin
> .Borders.ColorIndex = 15
> end with
> End If
>
> --
> HTH...
>
> Jim Thomlinson
>
>
> "Seeker" wrote:
>
> > Please help to debug following code which was collected and restructured
> > several codes from the discussion groups. I intended to add a thick black
> > bottom border to upper row if two rows contain different data, and then add a
> > blank row in between, now correct number of rows has formatted with a thick
> > black bottom border but all placed start from the last row up.
> >
> > Expected result
> > AAAA
> > AAAA
> > AAAA 'thick bottom border
> > 'Empty row in between
> > BBBB
> > BBBB 'thick bottom border
> > 'Empty row in between
> > CCCC 'thick bottom border
> >
> > Dim LastRow As Long
> > Dim lngRow As Long
> >
> > LastRow = Cells(Rows.Count, "A").End(xlUp).Row
> > Range("A1:X" & LastRow).Select
> >
> > For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
> > If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
> >
> > Selection.Borders(xlEdgeTop).LineStyle = xlDot
> > Selection.Borders(xlEdgeTop).Weight = xlThin
> > Selection.Borders(xlEdgeTop).ColorIndex = 15
> >
> > Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
> > Selection.Borders(xlEdgeBottom).Weight = xlThick
> > Selection.Borders(xlEdgeBottom).ColorIndex = 1
> >
> > Selection.Borders(xlEdgeRight).LineStyle = xlDot
> > Selection.Borders(xlEdgeRight).Weight = xlThin
> > Selection.Borders(xlEdgeRight).ColorIndex = 15
> >
> > Selection.Borders(xlInsideVertical).LineStyle = xlDot
> > Selection.Borders(xlInsideVertical).Weight = xlThin
> > Selection.Borders(xlInsideVertical).ColorIndex = 15
> >
> > Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
> > Selection.Borders(xlInsideHorizontal).Weight = xlThin
> > Selection.Borders(xlInsideHorizontal).ColorIndex = 15
> >
> > Rows(lngRow).EntireRow.Insert
> > Else
> > Selection.Borders.LineStyle = xlDot
> > Selection.Borders.Weight = xlThin
> > Selection.Borders.ColorIndex = 15
> > End If
> > Rgds

 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      30th May 2009
this is a another approach.

Sub sometest()
Dim Lastcell As Range
Dim startcell As Range
Dim endcell As Range

Set Lastcell = Cells(Rows.Count, "A").End(xlUp)

Set startcell = Range("B2")
Set endcell = startcell.Cells(2, 1)

Do While (startcell.Row <= Lastcell.Row)

If startcell = endcell Then
Set endcell = endcell.Cells(2, 1)
Else
With Range(startcell.Cells(1, 0), endcell.Cells(0, 23))
If endcell.Row - startcell.Row > 1 Then
.Borders(xlInsideHorizontal).LineStyle = xlDot
.Borders(xlInsideHorizontal).Weight = xlThin
.Borders(xlInsideHorizontal).ColorIndex = 15
End If
.Borders(xlEdgeTop).LineStyle = xlDot
.Borders(xlEdgeTop).Weight = xlThin
.Borders(xlEdgeTop).ColorIndex = 15

.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlEdgeBottom).Weight = xlThick
.Borders(xlEdgeBottom).ColorIndex = 1

.Borders(xlEdgeRight).LineStyle = xlDot
.Borders(xlEdgeRight).Weight = xlThin
.Borders(xlEdgeRight).ColorIndex = 15

.Borders(xlInsideVertical).LineStyle = xlDot
.Borders(xlInsideVertical).Weight = xlThin
.Borders(xlInsideVertical).ColorIndex = 15

End With
endcell(1, 1).EntireRow.Insert

Set startcell = endcell
Set endcell = startcell.Cells(2, 1)
End If
Loop
End Sub

Keiji

Seeker wrote:
> Please help to debug following code which was collected and restructured
> several codes from the discussion groups. I intended to add a thick black
> bottom border to upper row if two rows contain different data, and then add a
> blank row in between, now correct number of rows has formatted with a thick
> black bottom border but all placed start from the last row up.
>
> Expected result
> AAAA
> AAAA
> AAAA 'thick bottom border
> 'Empty row in between
> BBBB
> BBBB 'thick bottom border
> 'Empty row in between
> CCCC 'thick bottom border
>
> Dim LastRow As Long
> Dim lngRow As Long
>
> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
> Range("A1:X" & LastRow).Select
>
> For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
> If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
>
> Selection.Borders(xlEdgeTop).LineStyle = xlDot
> Selection.Borders(xlEdgeTop).Weight = xlThin
> Selection.Borders(xlEdgeTop).ColorIndex = 15
>
> Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
> Selection.Borders(xlEdgeBottom).Weight = xlThick
> Selection.Borders(xlEdgeBottom).ColorIndex = 1
>
> Selection.Borders(xlEdgeRight).LineStyle = xlDot
> Selection.Borders(xlEdgeRight).Weight = xlThin
> Selection.Borders(xlEdgeRight).ColorIndex = 15
>
> Selection.Borders(xlInsideVertical).LineStyle = xlDot
> Selection.Borders(xlInsideVertical).Weight = xlThin
> Selection.Borders(xlInsideVertical).ColorIndex = 15
>
> Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
> Selection.Borders(xlInsideHorizontal).Weight = xlThin
> Selection.Borders(xlInsideHorizontal).ColorIndex = 15
>
> Rows(lngRow).EntireRow.Insert
> Else
> Selection.Borders.LineStyle = xlDot
> Selection.Borders.Weight = xlThin
> Selection.Borders.ColorIndex = 15
> End If
> Rgds

 
Reply With Quote
 
Seeker
Guest
Posts: n/a
 
      30th May 2009
keiji kounoike,
Your code works perfectly, million thanks.
Rgds

"keiji kounoike" <"kounoike AT mbh.nifty." wrote:

> this is a another approach.
>
> Sub sometest()
> Dim Lastcell As Range
> Dim startcell As Range
> Dim endcell As Range
>
> Set Lastcell = Cells(Rows.Count, "A").End(xlUp)
>
> Set startcell = Range("B2")
> Set endcell = startcell.Cells(2, 1)
>
> Do While (startcell.Row <= Lastcell.Row)
>
> If startcell = endcell Then
> Set endcell = endcell.Cells(2, 1)
> Else
> With Range(startcell.Cells(1, 0), endcell.Cells(0, 23))
> If endcell.Row - startcell.Row > 1 Then
> .Borders(xlInsideHorizontal).LineStyle = xlDot
> .Borders(xlInsideHorizontal).Weight = xlThin
> .Borders(xlInsideHorizontal).ColorIndex = 15
> End If
> .Borders(xlEdgeTop).LineStyle = xlDot
> .Borders(xlEdgeTop).Weight = xlThin
> .Borders(xlEdgeTop).ColorIndex = 15
>
> .Borders(xlEdgeBottom).LineStyle = xlContinuous
> .Borders(xlEdgeBottom).Weight = xlThick
> .Borders(xlEdgeBottom).ColorIndex = 1
>
> .Borders(xlEdgeRight).LineStyle = xlDot
> .Borders(xlEdgeRight).Weight = xlThin
> .Borders(xlEdgeRight).ColorIndex = 15
>
> .Borders(xlInsideVertical).LineStyle = xlDot
> .Borders(xlInsideVertical).Weight = xlThin
> .Borders(xlInsideVertical).ColorIndex = 15
>
> End With
> endcell(1, 1).EntireRow.Insert
>
> Set startcell = endcell
> Set endcell = startcell.Cells(2, 1)
> End If
> Loop
> End Sub
>
> Keiji
>
> Seeker wrote:
> > Please help to debug following code which was collected and restructured
> > several codes from the discussion groups. I intended to add a thick black
> > bottom border to upper row if two rows contain different data, and then add a
> > blank row in between, now correct number of rows has formatted with a thick
> > black bottom border but all placed start from the last row up.
> >
> > Expected result
> > AAAA
> > AAAA
> > AAAA 'thick bottom border
> > 'Empty row in between
> > BBBB
> > BBBB 'thick bottom border
> > 'Empty row in between
> > CCCC 'thick bottom border
> >
> > Dim LastRow As Long
> > Dim lngRow As Long
> >
> > LastRow = Cells(Rows.Count, "A").End(xlUp).Row
> > Range("A1:X" & LastRow).Select
> >
> > For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
> > If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
> >
> > Selection.Borders(xlEdgeTop).LineStyle = xlDot
> > Selection.Borders(xlEdgeTop).Weight = xlThin
> > Selection.Borders(xlEdgeTop).ColorIndex = 15
> >
> > Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
> > Selection.Borders(xlEdgeBottom).Weight = xlThick
> > Selection.Borders(xlEdgeBottom).ColorIndex = 1
> >
> > Selection.Borders(xlEdgeRight).LineStyle = xlDot
> > Selection.Borders(xlEdgeRight).Weight = xlThin
> > Selection.Borders(xlEdgeRight).ColorIndex = 15
> >
> > Selection.Borders(xlInsideVertical).LineStyle = xlDot
> > Selection.Borders(xlInsideVertical).Weight = xlThin
> > Selection.Borders(xlInsideVertical).ColorIndex = 15
> >
> > Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
> > Selection.Borders(xlInsideHorizontal).Weight = xlThin
> > Selection.Borders(xlInsideHorizontal).ColorIndex = 15
> >
> > Rows(lngRow).EntireRow.Insert
> > Else
> > Selection.Borders.LineStyle = xlDot
> > Selection.Borders.Weight = xlThin
> > Selection.Borders.ColorIndex = 15
> > End If
> > Rgds

>

 
Reply With Quote
 
keiji kounoike
Guest
Posts: n/a
 
      30th May 2009
Thanks for your feedback.

Keiji

Seeker wrote:
> keiji kounoike,
> Your code works perfectly, million thanks.
> Rgds
>
> "keiji kounoike" <"kounoike AT mbh.nifty." wrote:
>
>> this is a another approach.
>>
>> Sub sometest()
>> Dim Lastcell As Range
>> Dim startcell As Range
>> Dim endcell As Range
>>
>> Set Lastcell = Cells(Rows.Count, "A").End(xlUp)
>>
>> Set startcell = Range("B2")
>> Set endcell = startcell.Cells(2, 1)
>>
>> Do While (startcell.Row <= Lastcell.Row)
>>
>> If startcell = endcell Then
>> Set endcell = endcell.Cells(2, 1)
>> Else
>> With Range(startcell.Cells(1, 0), endcell.Cells(0, 23))
>> If endcell.Row - startcell.Row > 1 Then
>> .Borders(xlInsideHorizontal).LineStyle = xlDot
>> .Borders(xlInsideHorizontal).Weight = xlThin
>> .Borders(xlInsideHorizontal).ColorIndex = 15
>> End If
>> .Borders(xlEdgeTop).LineStyle = xlDot
>> .Borders(xlEdgeTop).Weight = xlThin
>> .Borders(xlEdgeTop).ColorIndex = 15
>>
>> .Borders(xlEdgeBottom).LineStyle = xlContinuous
>> .Borders(xlEdgeBottom).Weight = xlThick
>> .Borders(xlEdgeBottom).ColorIndex = 1
>>
>> .Borders(xlEdgeRight).LineStyle = xlDot
>> .Borders(xlEdgeRight).Weight = xlThin
>> .Borders(xlEdgeRight).ColorIndex = 15
>>
>> .Borders(xlInsideVertical).LineStyle = xlDot
>> .Borders(xlInsideVertical).Weight = xlThin
>> .Borders(xlInsideVertical).ColorIndex = 15
>>
>> End With
>> endcell(1, 1).EntireRow.Insert
>>
>> Set startcell = endcell
>> Set endcell = startcell.Cells(2, 1)
>> End If
>> Loop
>> End Sub
>>
>> Keiji
>>
>> Seeker wrote:
>>> Please help to debug following code which was collected and restructured
>>> several codes from the discussion groups. I intended to add a thick black
>>> bottom border to upper row if two rows contain different data, and then add a
>>> blank row in between, now correct number of rows has formatted with a thick
>>> black bottom border but all placed start from the last row up.
>>>
>>> Expected result
>>> AAAA
>>> AAAA
>>> AAAA 'thick bottom border
>>> 'Empty row in between
>>> BBBB
>>> BBBB 'thick bottom border
>>> 'Empty row in between
>>> CCCC 'thick bottom border
>>>
>>> Dim LastRow As Long
>>> Dim lngRow As Long
>>>
>>> LastRow = Cells(Rows.Count, "A").End(xlUp).Row
>>> Range("A1:X" & LastRow).Select
>>>
>>> For lngRow = Cells(Rows.Count, 2).End(xlUp).Row To 2 Step -1
>>> If Range("B" & lngRow) <> Range("B" & lngRow - 1) Then
>>>
>>> Selection.Borders(xlEdgeTop).LineStyle = xlDot
>>> Selection.Borders(xlEdgeTop).Weight = xlThin
>>> Selection.Borders(xlEdgeTop).ColorIndex = 15
>>>
>>> Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
>>> Selection.Borders(xlEdgeBottom).Weight = xlThick
>>> Selection.Borders(xlEdgeBottom).ColorIndex = 1
>>>
>>> Selection.Borders(xlEdgeRight).LineStyle = xlDot
>>> Selection.Borders(xlEdgeRight).Weight = xlThin
>>> Selection.Borders(xlEdgeRight).ColorIndex = 15
>>>
>>> Selection.Borders(xlInsideVertical).LineStyle = xlDot
>>> Selection.Borders(xlInsideVertical).Weight = xlThin
>>> Selection.Borders(xlInsideVertical).ColorIndex = 15
>>>
>>> Selection.Borders(xlInsideHorizontal).LineStyle = xlDot
>>> Selection.Borders(xlInsideHorizontal).Weight = xlThin
>>> Selection.Borders(xlInsideHorizontal).ColorIndex = 15
>>>
>>> Rows(lngRow).EntireRow.Insert
>>> Else
>>> Selection.Borders.LineStyle = xlDot
>>> Selection.Borders.Weight = xlThin
>>> Selection.Borders.ColorIndex = 15
>>> End If
>>> Rgds

 
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
Cannot Debug .NET code behind Erosha Microsoft Outlook Form Programming 1 4th Aug 2008 01:58 PM
Cannot debug from unmanged code into managed code B. Microsoft VC .NET 6 12th Oct 2006 02:06 AM
Debug Code Tee See Microsoft Access Getting Started 2 2nd May 2006 07:49 PM
How to tell if your C# code is running in debug mode (debug compil =?Utf-8?B?TWF4IE0uIFBvd2Vy?= Microsoft C# .NET 3 20th Oct 2005 10:39 PM
Help: Cant debug ASP.NET code VB Programmer Microsoft ASP .NET 3 27th Jun 2003 05:39 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:56 PM.