Sometimes, we want to add a slash header in Excel, but Excel does not provide the function of making slash head, each time to draw a slash manually, very troublesome. Is there a solution? In fact, we can use VBA code can write a function, a key insert Excel slash header.
With the command button control in the Control Toolbox, draw a command button on the worksheet, change the "Caption" property to "one-click Insert Slash Header", and double-click the button to write code in the "click" Event, where the key code is as follows.
Key code:
' Get row and column headings
Dim Icol, IRow as String
Icol=inputbox ("Please enter row header for slash cell", row heading)
Irow=inputbox ("Please enter column headings for slash cells", column headings)
Selection.value = Icol + "" + IRow
' Judge if the string is in line with the rules
If Len (Icol) = 0 or len (irow) = 0 Then
MsgBox ("The title entered is empty!")
Exit Sub
End If
' Determines whether a selection has only one cell
If selection.count <> 1 Then
MsgBox ("Please select a cell and do this again!")
Exit Sub
End If
' Set the slash on top left to right
With Selection.borders (Xldiagonaldown)
. LineStyle = xlcontinuous
. Weight = Xlthin
. ColorIndex = xlautomatic
End With
Once the code is written, when you need to insert a slash header, select the cell that you want to insert a slash header in (if the selected cell is more than one, the system will give the error prompt), click the "one-click Insert Slash Header" button, you will be prompted to enter the header row, column headings, respectively, enter the header row header (for example, week) and column headings (for example, classes). Very convenient.
Computer Tutorials