


Excel VBA code: Merge child rows to parent rows, the result is parent row 1 and its children
A piece of excel vba code is used to merge the child table rows into the parent table. The result is: several parent rows 1
Assuming your first line is the title line start with the second line
Sub merge()
Endcol1 = Sheet1.[iv1].End(xlToLeft).Column
endrow1 = Sheet1.Range("B65536").End(xlUp).Row
endcol2 = Sheet2.[iv1].End(xlToLeft).Column
endrow2 = Sheet2.Range("B65536").End(xlUp).Row
Dim A As Range
Dim BiaoYiID As Range
Dim BiaoErID As Range
Dim MyRange1 As Range
Dim BiaoErH As Range
Dim leiji As Long
Sheet2.Activate
Set BiaoErID = Sheet2.Range(Cells(2, 2), Cells(endrow2, 2))
For i = 2 To endrow1
sxh = i lieji
lieji1 = 0
biaoerneirong = Sheet1.Range("B" & sxh).Text
Set A = BiaoErID.Find(biaoerneirong, after:=BiaoErID.Cells(BiaoErID.Cells.Count), lookat:=xlWhole)
If Not A Is Nothing Then
biaoertopaddress = A.Address
Do
sxh1 = sxh lieji1
BIAORADDRESS = A.Address(RowAbsolute:=False, ColumnAbsolute:=False)
biaoyiaddress = Sheet1.Range("B" & sxh1).Address(RowAbsolute:=False, ColumnAbsolute:=False)
Sheet1.Select
Sheet1.Range(biaoyiaddress).Offset(1).Activate
ActiveCell.EntireRow.Insert
lieji = lieji 1
lieji1 = lieji1 1
For ii = 0 To endcol2
ActiveCell.Offset(0, ii) = Sheet2.Range(BIAORADDRESS).Offset(0, ii)
Next
Set A = BiaoErID.FindNext(A)
Loop While Not A Is Nothing And A.Address biaoertopaddress
End If
Next
End Sub
How to write a VBA code to count the number of worksheets in a workbook
Sub worksheet number statistics ()
If Sheets(1).Name "Statistics on the number of worksheets" Then
yn = MsgBox ("[Worksheet Quantity Statistics] worksheet does not exist, create [Worksheet Quantity Statistics]?", vbYesNo, "Create [Worksheet Quantity Statistics] worksheet")
If yn = vbYes Then
Sheets.Add(Sheets(1)).Name = "Statistics on the number of worksheets"
End
End If
End If
Sheets ("Statistics on the number of worksheets").Select
Range("A1").Select
Cells(1, 1).Value = "The number of worksheets is"
Cells(1, 2).Value = Sheets.Count
End Sub
A worksheet named Worksheet Statistics will be created, and the number of worksheets will be displayed in the first row
Please experts write comments for the following excel VBA code. Please write the comments as detailed as possible. Thank you
Public m& 'Define public variable m
Sub lqxs()
Dim Arr, i&, Brr(1 To 27, 1 To 23), rq, nl 'Define the above variables, Brr is a two-dimensional array with 27 rows and 23 columns
Sheet1.Activate 'Make sheet1 the currently active sheet
[c5:z32].ClearContents 'Clear the data in cells C5 to Z32
Myr = Sheet2.[a65536].End(xlUp).row 'Assign the number of rows in the area with data in column A of Sheet2 to the Myr variable
Arr = Sheet2.Range("a7:t" & Myr) 'Name the range from column A7 to column T and row Myr as Arr
For i = 1 To UBound(Arr) 'Loop
rq = DateSerial(Left(Arr(i, 7), 4), Mid(Arr(i, 7), 5, 2), Right(Arr(i, 7), 2)) 'Change G in Sheet2 The data in the column changes to date format, such as: 2013/12/12
nl = DateDiff("yyyy", rq, Now) 'Determine whether the year of the data date in column G in Sheet2 is the same as this year. If it is the same, 0 will be returned. If it is not the same, 1 will be returned.
Call jd(Arr(i, 13)) 'Call jd() function
Brr(1, nl 1) = Brr(1, nl 1) 1 'Add one to the value of array Brr(1, nl 1)
Brr(m, nl 1) = Brr(m, nl 1) 1 'Add one to the value of array Brr(1, nl 1)
Next
[d5].Resize(27, 23) = Brr 'Start by assigning the value of the array to cell D5, and go to the 22nd column on the right of the 26th row below
[c5].Formula = "=sum(rc[1]:rc[23])" 'Add formula to cell C5, C5=D5 E5 F5 AB5
[c5].AutoFill [c5].Resize(27, 1) 'Format filling Fill the format of C5 into cell C31
[d6].Formula = "=sum(r[1]c:r[4]c)" 'Add formula to cell D6, D6=D7 D8 D9 D10
[d6].AutoFill [d6].Resize(1, 23) 'Format filling, fill the format of D6 into cell AB31
End Sub
The above is the detailed content of Excel VBA code: Merge child rows to parent rows, the result is parent row 1 and its children. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Ditch the Calculator: Why and How to Use Excel for All Your Calculations I haven't touched a calculator in ages. Why? Because Microsoft Excel handles all my calculations with ease, and it can do the same for you. Why Excel Trumps a Calculator While

Creating tables in Word, although improved, is still cumbersome and sometimes brings more problems. This is why you should always create tables in Microsoft Excel. Why is it better to create tables in Excel? In short, Word is a word processor, while Excel is a data processor. So Word is not built for the best table creation, but its similar product, Excel. Here are just some of the reasons why creating tables in Excel is better than using Microsoft Word: Although it is surprising that you can use many Excel-like features in Microsoft Word tables, in Excel you

Enhance Your Excel Charts: Reducing Gaps Between Bars and Columns Presenting data visually in charts significantly improves spreadsheet readability. Excel excels at chart creation, but its extensive menus can obscure simple yet powerful features, suc

Quick View of AVERAGEIF and AVERAGEIFS Functions in Excel Excel's AVERAGEIF and AVERAGEIFS functions can be used to calculate the average value of a dataset. However, unlike simpler AVERAGE functions, they are able to include or exclude specific values in the calculation. How to use the AVERAGEIF function in Excel Excel's AVERAGEIF function allows you to calculate the average value of a filtered dataset based on a single condition set. AVERAGEIF function syntax The AVERAGEIF function contains three parameters: =AVERAGEIF(x,y,z)

Excel web version features enhancements to improve efficiency! While Excel desktop version is more powerful, the web version has also been significantly improved over the past year. This article will focus on five key improvements: Easily insert rows and columns: In Excel web, just hover over the row or column header and click the " " sign that appears to insert a new row or column. There is no need to use the confusing right-click menu "insert" function anymore. This method is faster, and newly inserted rows or columns inherit the format of adjacent cells. Export as CSV files: Excel now supports exporting worksheets as CSV files for easy data transfer and compatibility with other software. Click "File" > "Export"

Master Microsoft Excel with these essential keyboard shortcuts! This cheat sheet provides quick access to the most frequently used commands, saving you valuable time and effort. It covers essential key combinations, Paste Special functions, workboo

Excel's LAMBDA Functions: An easy guide to creating custom functions Before Excel introduced the LAMBDA function, creating a custom function requires VBA or macro. Now, with LAMBDA, you can easily implement it using the familiar Excel syntax. This guide will guide you step by step how to use the LAMBDA function. It is recommended that you read the parts of this guide in order, first understand the grammar and simple examples, and then learn practical applications. The LAMBDA function is available for Microsoft 365 (Windows and Mac), Excel 2024 (Windows and Mac), and Excel for the web. E

Quick Links Why Use the Camera Tool?
