Automatically populate data using EXCEL VBA

WBOY
Release: 2024-01-22 18:33:05
forward
1240 people have browsed it

EXCEL VBA fill content

Sub S()

a = [o2].Text

b = [o7].Text

na = Len(a)

nb = Len(b)

ReDim arr(1 To na)

ReDim brr(1 To nb)

For i = 1 To na

arr(i) = Val(Mid(a, i, 1))

Next

For i = 1 To nb

brr(i) = Val(Mid(b, i, 1))

Next

For i = 1 To 9

a = """

b = """

For j = 1 To na

a = a & (arr(j) i) Mod 10

Next

For j = 1 To nb

b = b & (brr(j) i) Mod 10

Next

[o2].Offset(0, i) = a

[o7].Offset(0, i) = b

Next

End Sub

Questions about VBA autofill

The code to find the last row with data in column c is:

i=Cells(Rows.Count, 3).End(xlUp).Row

Selection.AutoFill Destination:=Range("D5:D" & i &"")

The complete code is:

Sub jj()

Range("D5").Select

ActiveCell.FormulaR1C1 = "=IF(RC[-2]=RC[-1],""y",""0"")"

i = Cells(Rows.Count, 3).End(xlUp).Row

Selection.AutoFill Destination:=Range("D5:D" & i & """)

End Sub

How to use VBA code to sort cells in a part of EXCEL from small to large

Because the screenshots are incomplete, I will assume that the data area is A1:F9 and the filling area is H1:M9

code show as below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim arr1(1 To 54), arr2(1 To 54)

Dim x, y, z As Integer

Dim b, c

Dim a As Variant

z = 1

x = 1

y = 1

c = 1

For x = 1 To 9

For y = 1 To 6

arr1(z) = Cells(x, y)

z = z 1

Next y

Next x

z = z - 1

For z = 1 To 54

a = arr1(z)

b = z

For x = 1 To 54

If a

a = arr1(x)

b = x

End If

Next x

arr2(c) = a

c = c 1

arr1(b) = 0

Next z

c = c - 1

For x = 1 To 9

For y = 8 To 13

Cells(x, y) = arr2(c)

c = c - 1

Next y

Next x

End Sub

EXCEL VBA填充内容

operation result

If this helped you, please accept it, thank you^_^

excel vba fill cells

Owner: Hello, there is a prerequisite for your question:

If your Excel version is version 2003, then you can only use the 56 colors preset by the system. Other fill colors implemented using VBA code will be converted to the one closest to these 56 colors.

If your Excel version is 2007 and above, there are almost no restrictions on cell fill colors. You can completely implement custom color fills through the cell fill command. It supports RGB and HSL modes without resorting to VBA.

If using VBA, the code is as follows:

Sub test() 'Fill cell A1 with red, RGB (red, green, blue). The values ​​of red, green and blue range from 0 to 255. Different values ​​can be set to obtain different colors. Range("A1").Interior.Color = RGB(255, 0, 0) 'Fill with red 'If you want to remove the fill color, use this sentence Range("A1").Interior.Pattern = xlnoeEnd Sub

The above is the detailed content of Automatically populate data using EXCEL VBA. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:docexcel.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template