Форматирование, замена и перефразирование - PullRequest
0 голосов
/ 09 ноября 2018

Мне нужна помощь, чтобы связать мой код и найти решения для частей, по которым я не смог найти четкую информацию. Первая часть кода, я думаю, я кое-что понял, но с остальной мне нужна помощь. Код будет связан с 1 командной кнопкой на листе. Я постоянно получаю один и тот же отчет два раза в неделю, и моя задача - переформатировать его. Это научит меня ВБА и может сэкономить много времени, если я смогу понять это с вашей помощью! Пожалуйста, оставьте примечания в ваших кодах, чтобы я мог учиться и понимать. Спасибо всем, кто помогает.

Это мой текущий код:

Private Sub CommandButton1_Click()

'This section works, but needs to be linked to sequence
'First Step 'Entire Worksheet Wrap Text, Align vertical 
    Worksheets("Page1").Cells.Selectcentered and All Borders
    With Selection
    .WrapText = True
    .VerticalAlignment = xlCenter
    .Cells.Borders.LineStyle = xlContinuous
    End With


'This section works, but needs to be linked to sequence
'Second Step 'Hide Specified Column
    Worksheets("Page1").Range("H1,I1,J1,K1,L1,N1")
    .EntireColumn.Hidden = True


'This section works, but needs to be linked to sequence
Second Step Part 2
    Worksheets("Page1").Range("P1,Q1").EntireColumn.Delete = True

'This section works, but needs to be linked to sequence & it needs to stop after there is no more data
'Third Step 'Bold First Row of Worksheet
Rows(1).Columns(1:15)Select 
    Selection.Font.Bold = True
    Selection.WrapText = True
    Selection.VerticalAlignment = xlCenter
    Selection.HorizontalAlignment = xlCenter
    Selection.Interior.Color = RGB(164, 213, 93) 'Fill in background of selected cells

'This section works, but needs to be linked into sequence
'Fourth Step
'Align each defined column to be centered
    Worksheets("Page1").Range("F1,G1,M1").EntireColumn
    .HorizontalAlignment = xlCenter

'This section works, but needs to be linked to sequence
'Fifth Step
'Make column O 42.0 width
    Columns("O").RowHeight = 42

'This section works, but needs to be linked to sequence
'Sixth Step
'Change each negative number to a zero in Column M if a negative number is present
    Dim ws As Worksheet
    Dim rg As Range
    For Each ws In ActiveWorkbook.Worksheets
    For Each rg In ws.UsedRange
        If rg.Value < 0 Then
            rg.Value = 0
        End If
    Next rg
Next ws

'This section needs help!
'Seventh Step
'Change numeric value e.g. 10/24 to date such as Oct 24.  Has to find on the column specified as it will include other text with the numbers e.g. It will be available 11/01 (Nov 1)
    Label1.Text = Format(Expression, "O")


'This section needs help!
'Eighth Step
'At the end of a row add a period if a period isn't present.  Remove excess spacing before and after period.
'IF(RIGHT(TRIM(O4),1)=".",O4,O4&".")

'This section needs help!
'Ninth Step
'If the phrase says: Available to order today. Change it to say: More stock will be made available today.
    Dim i As Long
    Dim TargetList
    Dim MyRange As Range
    TargetList = Array("You can add multiple target lists with different phrases?")
    Dim sStringToAdd As String

    sStringToAdd = "(More stock will be made available today.)"

    For i = "(Available to order today.)" To UBound(TargetList)

    Set MyRange = ActiveSheets.Content

    MyRange.Find.Execute FindText:=TargetList(i), 
    ReplaceWith:=TargetList(i) & sStringToAdd, _
    Replace:=wdReplaceAll
    Next i


'This section needs help!
'Tenth Step
'Change M1 to say Available Now


'This section needs help!
'Eleventh Step
'Change O1 to say These Dates Reflect the First Day You Can Order this Item from Sysco


'This section needs help!
'Twelveth
'Modify page break to include Column O, but remove all other page breaks.
    Worksheets("Page1").VPageBreaks.Add Before = Columns("P")
    Worksheets("Page1").Columns("P").PageBreak = xlPageBreakManual

'This section works, but needs to be linked into sequence
'Thirteen Step
'Change page orientation to landscape and vertically center page for printing
    With ActiveSheet.PageSetup
    .Orientation = xlLandscape
    .CenterHorizontally = True
    End With


'This section needs help!
'Fourteen Step
'Add header as Centered saying LTC SAB Update "Today's Date" or have it say LTC NAB Update "Today's Date".  Is there a way it can pick out the name of the document to determine if it should say SAB or NAB (as that's where it can verify which one to choose).
    .CenterHeader="LTC NAB Stock Update" InsertAfter.TodaysDate
    End With

    End Sub
...