


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!

This tutorial unlocks the power of Excel's Paste Special feature, showing you how to significantly boost your efficiency with paste special shortcuts. Learn to paste values, formulas, comments, formats, column widths, and more, all while avoiding co

This tutorial shows you how to efficiently add, modify, and delete multiple checkboxes in Excel. Last week, we explored using checkboxes for checklists, conditional formatting, interactive reports, and dynamic charts. This week, we'll focus on the

This tutorial explores six methods for inserting checkmarks in Excel, along with formatting and counting techniques. Excel offers two checkmark types: interactive checkboxes and tick symbols. Checkboxes allow selection/deselection via mouse clicks

The tutorial shows different ways to get age from birthday in Excel. You will learn a handful of formulas to calculate age as a number of complete years, get exact age in years, months and days at today's date or a particular date. There

This tutorial demonstrates how to add a drop-down calendar (date picker) to Excel and link it to a cell. It also shows how to quickly create a printable calendar using an Excel template. Data integrity is a major concern in large or shared spreadshe

Improve Excel’s productivity: A guide to efficient naming worksheets This article will guide you on how to effectively name Excel worksheets, improve productivity and enhance accessibility. Clear worksheet names significantly improve navigation, organization, and cross-table references. Why rename Excel worksheets? Using the default "Sheet1", "Sheet2" and other names is inefficient, especially in files containing multiple worksheets. Clearer names like “Dashboard,” “Sales,” and “Forecasts,” give you and others a clear picture of the workbook content and quickly find the worksheets you need. Use descriptive names (such as "Dashboard", "Sales", "Forecast")

This comprehensive guide explains how to effectively manage your Outlook email storage by archiving emails, tasks, and other items across various Outlook versions (365, 2021, 2019, 2016, 2013, and earlier). Learn to configure automatic archiving, pe

The tutorial shows how to compare text strings in Excel for case-insensitive and exact match. You will learn a number of formulas to compare two cells by their values, string length, or the number of occurrences of a specific character, a


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

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment