Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Add borders to certain cells using VBA

I have a schedule file in Excel that I am trying to automatically create
borders on certain cells. The schedule file is made up of 4 worksheets,
First Shift, Second Shift, Third Shift and Unit Totals. There are 3
different Units, each with it's own schedule workbook. The Units are made
up of living units, and they have different numbers of schedules.

You can find a sample copy of the schedules at the following link,
http://www.swvtc.dmhmrsas.virginia.gov/sched/

Now for my question. How can I develop a macro to scan through a certain
row (say 5) and find the value W (for Wednesday) and then create a left
border for that cell and all the cells below it to a certain cell, and then
return to Row 5 and continue on until it encounters W again, and does it
again. The reason for this is to denote the workweek, which runs from
Wednesday to Tuesday.

It doesn't matter to me if I have to hand-code each different schedule,
since this will only be run once every few years.

Thanks,
Drew Laing


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Add borders to certain cells using VBA

Try:

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = r.Rows.Count + r.Row - 1
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub


--
Gary's Student


"Drew" wrote:

I have a schedule file in Excel that I am trying to automatically create
borders on certain cells. The schedule file is made up of 4 worksheets,
First Shift, Second Shift, Third Shift and Unit Totals. There are 3
different Units, each with it's own schedule workbook. The Units are made
up of living units, and they have different numbers of schedules.

You can find a sample copy of the schedules at the following link,
http://www.swvtc.dmhmrsas.virginia.gov/sched/

Now for my question. How can I develop a macro to scan through a certain
row (say 5) and find the value W (for Wednesday) and then create a left
border for that cell and all the cells below it to a certain cell, and then
return to Row 5 and continue on until it encounters W again, and does it
again. The reason for this is to denote the workweek, which runs from
Wednesday to Tuesday.

It doesn't matter to me if I have to hand-code each different schedule,
since this will only be run once every few years.

Thanks,
Drew Laing



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Add borders to certain cells using VBA

That works, with a few changes,

On more question, how can I specify to use .Weight = xlMedium, I tried, but
it kept erroring out.

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = 12
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub

Since there are more than 1 schedules on each worksheet, I needed to limit
the nlastrow to a cell.

Thanks,
Drew Laing


"Gary''s Student" wrote in message
...
Try:

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = r.Rows.Count + r.Row - 1
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub


--
Gary's Student


"Drew" wrote:

I have a schedule file in Excel that I am trying to automatically create
borders on certain cells. The schedule file is made up of 4 worksheets,
First Shift, Second Shift, Third Shift and Unit Totals. There are 3
different Units, each with it's own schedule workbook. The Units are
made
up of living units, and they have different numbers of schedules.

You can find a sample copy of the schedules at the following link,
http://www.swvtc.dmhmrsas.virginia.gov/sched/

Now for my question. How can I develop a macro to scan through a certain
row (say 5) and find the value W (for Wednesday) and then create a left
border for that cell and all the cells below it to a certain cell, and
then
return to Row 5 and continue on until it encounters W again, and does it
again. The reason for this is to denote the workweek, which runs from
Wednesday to Tuesday.

It doesn't matter to me if I have to hand-code each different schedule,
since this will only be run once every few years.

Thanks,
Drew Laing





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Add borders to certain cells using VBA

For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Cells(j, i).Borders(xlEdgeLeft).Weight = xlMedium
Next

--
Gary's Student


"Drew" wrote:

That works, with a few changes,

On more question, how can I specify to use .Weight = xlMedium, I tried, but
it kept erroring out.

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = 12
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub

Since there are more than 1 schedules on each worksheet, I needed to limit
the nlastrow to a cell.

Thanks,
Drew Laing


"Gary''s Student" wrote in message
...
Try:

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = r.Rows.Count + r.Row - 1
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub


--
Gary's Student


"Drew" wrote:

I have a schedule file in Excel that I am trying to automatically create
borders on certain cells. The schedule file is made up of 4 worksheets,
First Shift, Second Shift, Third Shift and Unit Totals. There are 3
different Units, each with it's own schedule workbook. The Units are
made
up of living units, and they have different numbers of schedules.

You can find a sample copy of the schedules at the following link,
http://www.swvtc.dmhmrsas.virginia.gov/sched/

Now for my question. How can I develop a macro to scan through a certain
row (say 5) and find the value W (for Wednesday) and then create a left
border for that cell and all the cells below it to a certain cell, and
then
return to Row 5 and continue on until it encounters W again, and does it
again. The reason for this is to denote the workweek, which runs from
Wednesday to Tuesday.

It doesn't matter to me if I have to hand-code each different schedule,
since this will only be run once every few years.

Thanks,
Drew Laing






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Add borders to certain cells using VBA

Great!

Thanks a bunch,
Drew

"Gary''s Student" wrote in message
...
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Cells(j, i).Borders(xlEdgeLeft).Weight = xlMedium
Next

--
Gary's Student


"Drew" wrote:

That works, with a few changes,

On more question, how can I specify to use .Weight = xlMedium, I tried,
but
it kept erroring out.

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = 12
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub

Since there are more than 1 schedules on each worksheet, I needed to
limit
the nlastrow to a cell.

Thanks,
Drew Laing


"Gary''s Student" wrote in
message
...
Try:

Sub gsnu()
Dim r As Range
Set r = ActiveSheet.UsedRange
nlastrow = r.Rows.Count + r.Row - 1
For i = 1 To 255
If Cells(5, i).Value = "W" Then
For j = 5 To nlastrow
Cells(j, i).Borders(xlEdgeLeft).LineStyle = xlContinuous
Next
End If
Next
End Sub


--
Gary's Student


"Drew" wrote:

I have a schedule file in Excel that I am trying to automatically
create
borders on certain cells. The schedule file is made up of 4
worksheets,
First Shift, Second Shift, Third Shift and Unit Totals. There are 3
different Units, each with it's own schedule workbook. The Units are
made
up of living units, and they have different numbers of schedules.

You can find a sample copy of the schedules at the following link,
http://www.swvtc.dmhmrsas.virginia.gov/sched/

Now for my question. How can I develop a macro to scan through a
certain
row (say 5) and find the value W (for Wednesday) and then create a
left
border for that cell and all the cells below it to a certain cell, and
then
return to Row 5 and continue on until it encounters W again, and does
it
again. The reason for this is to denote the workweek, which runs from
Wednesday to Tuesday.

It doesn't matter to me if I have to hand-code each different
schedule,
since this will only be run once every few years.

Thanks,
Drew Laing








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
Find cells without borders Marc C Excel Discussion (Misc queries) 0 February 21st 08 08:56 PM
printing cells with borders Jackie D Excel Discussion (Misc queries) 2 July 23rd 06 03:18 PM
Borders around cells... syuhas[_2_] Excel Programming 1 February 28th 06 05:16 PM
Borders Don't Line up with Cells. Michael Hesse Excel Discussion (Misc queries) 0 August 30th 05 04:08 PM
Borders around cells Michelle Excel Programming 1 June 30th 04 06:33 PM


All times are GMT +1. The time now is 12:50 PM.

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"