我需要帮助将我的代码链接在一起,并找到无法找到明确信息的部分的解决方案。我认为我已经弄清了代码的第一部分,但其余部分需要帮助。该代码将链接到图纸上的1个命令按钮。我每周两次都会收到相同的报告,而我的工作是重新设置格式。它会教我vba,如果我能在您的帮助下解决这个问题,它可以节省很多时间!请在您的代码中留下注释,以便我学习和理解。谢谢所有提供帮助的人。
这是我当前的代码:
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