[Learning point: excel in VBA] 2

Source: Internet
Author: User

(1) create a form in VBA, initialize its location, and call it...

 

 Sub CallForm ()
UserForm1.Show 'display form
UserForm1.Left = 600 'display position
UserForm1.Top = 180
End Sub


Private Sub commandbutton#click ()
CallForm 'call
End Sub

 

 

(2) font color and background color of cells in Excel


Code

  Private Sub commandbutton#click ()
Dim I, j, k As Integer
J = 0
K = 0
L = 0
M = 0

For I = 1 To 10

If Cells (I, 1). Font. Color = 0 Then ', the Font Color is black.
J = j + 1
End If

If Cells (I, 1). Font. Color = 255 Then ', the Font Color is red.
K = k + 1
End If

If cells (I, 2). Interior. Color = & hffffff then', the background color is white.
L = L + 1
End if

If cells (I, 2). Interior. Color = & HFF then ', the background color is red.
M = m + 1
End if

Next I

Dim FC, BC as string

Fc = "Red =" & K & ", black =" & J
Msgbox (FC)

BC = "White =" & L & ", Red =" & M
Msgbox (BC)
End sub

 

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.