Results 1 to 3 of 3

Thread: vba excel

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2000
    Location
    bebenia, PA, USA
    Posts
    241

    Private Sub Workbook_Open()
    Dim stRangeCol As String
    Dim intRangeRowBegin As Integer
    Dim intRangeRowEnd As Integer
    Dim Pos As String
    Dim intloc As Integer
    Dim intc As Integer
    Application.DisplayAlerts = False
    ActiveCell.CurrentRegion.Select
    stRangeCol = "a"
    intRangeRowBegin = 7
    Pos = stRangeCol & intRangeRowBegin
    Range(Pos).Select
    If ActiveCell.Value <> Empty Then
    intc = intRangeRowBegin
    Do Until ActiveCell.Value = Empty
    Pos = "A" & intc
    Range(Pos).Select
    intc = intc + 1
    Loop
    intRangeRowEnd = intc - 2
    Pos = "A" & intRangeRowEnd
    Range(Pos).Select
    If ActiveCell.Value <> "Saturday" Then
    intRangeRowBegin = intc - 7
    Else
    intRangeRowBegin = intc - 6
    End If
    Pos = "A" & intRangeRowBegin & ":A" & intRangeRowEnd
    Range(Pos).Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 90
    .AddIndent = False
    .ShrinkToFit = False
    .MergeCells = True
    End With
    With Selection.Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 10
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    End With
    With Selection.Interior
    .ColorIndex = 19
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    End With
    Pos = "A" & intRangeRowBegin & ":L" & intRangeRowEnd
    Range(Pos).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    End If
    End Sub


    can someone take this apart and tell me what it is doing line by line; please thanks!!!

  2. #2
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Originally posted by Bebe

    Private Sub Workbook_Open()
    Dim stRangeCol As String
    Dim intRangeRowBegin As Integer
    Dim intRangeRowEnd As Integer
    Dim Pos As String
    Dim intloc As Integer
    Dim intc As Integer
    Application.DisplayAlerts = False
    ActiveCell.CurrentRegion.Select
    stRangeCol = "a"
    intRangeRowBegin = 7
    Pos = stRangeCol & intRangeRowBegin
    '*** start at cell A7 and loop until you find an empty column
    Range(Pos).Select
    If ActiveCell.Value <> Empty Then
    intc = intRangeRowBegin
    Do Until ActiveCell.Value = Empty
    Pos = "A" & intc
    Range(Pos).Select
    intc = intc + 1
    Loop
    intRangeRowEnd = intc - 2
    '*** set the last position to 2 less than the last empty column in the row
    Pos = "A" & intRangeRowEnd
    Range(Pos).Select
    '*** if the last cell, that has data, contains the word
    "Saturday" set the starting position to the (end position + 1) -7 otherwise set it to the (end position + 1) - 6
    If ActiveCell.Value <> "Saturday" Then
    intRangeRowBegin = intc - 7
    Else
    intRangeRowBegin = intc - 6
    End If

    '*** the following code takes the selected range of cells and formats them (by setting the font, the spacing, cell boundary styles; etc.)

    Pos = "A" & intRangeRowBegin & ":A" & intRangeRowEnd
    Range(Pos).Select
    With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlCenter
    .WrapText = False
    .Orientation = 90
    .AddIndent = False
    .ShrinkToFit = False
    .MergeCells = True
    '*** the above values tell Excel how to format the cells in the selected range
    End With
    With Selection.Font
    .Name = "Arial"
    .FontStyle = "Bold"
    .Size = 10
    .Strikethrough = False
    .Superscript = False
    .Subscript = False
    .OutlineFont = False
    .Shadow = False
    .Underline = xlUnderlineStyleNone
    .ColorIndex = xlAutomatic
    '*** the above commands tell excell how to set the font data in the cells
    End With
    With Selection.Interior
    .ColorIndex = 19
    .Pattern = xlSolid
    .PatternColorIndex = xlAutomatic
    '*** the above commands tell Excel the color values for the range of cells
    End With
    Pos = "A" & intRangeRowBegin & ":L" & intRangeRowEnd
    Range(Pos).Select
    '*** from here to the end of formatting it's drawing a box adround the range of cells
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
    End With
    End If
    '*** end cell formatting
    End Sub


    can someone take this apart and tell me what it is doing line by line; please thanks!!!

  3. #3
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    I should've mentioned that it looks like the person that created the above code probably turned on Macro's in Excel, recorded a set of commands and copied them into VB, modifying as needed...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width