How to dynamically set Excel slash headers in VBA

Source: Internet
Author: User

If you need to draw a diagonal header directly, you'll need to use the VBA method, and the following is relevant, please continue reading.

With the command button control in the Control Toolbox, draw a command button on the worksheet, change the "Caption" property to "direct 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

This feature is used in the following ways:

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 an error prompt, click the "make slash head directly" button, you will be prompted to enter the header row, column headings, respectively, enter the header row headings (such as grades) and column headings (for example, classes).

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.