1.åå§æ°æ®æå¨å·¥ä½ç°¿å
å«å¤ä¸ªæ ¼å¼ç¸åçå·¥ä½è¡¨ï¼åªä¸è¿æ¯ä¸ªå·¥ä½è¡¨å
容ä¸åï¼æ¯å¦è¯´ä¸å人åçå·¥ä½è¡¨æ°æ®æè
ä¸åé¨é¨å¡«åçæ°æ®ã
2.å¨åå§æ°æ®åç®å½ä¸æ°å»ºä¸ä¸ªå·¥ä½ç°¿ï¼å»ºç«ä¸¤ä¸ªå·¥ä½è¡¨ï¼å称åå«ä¸ºâé¦é¡µâåâå并æ±æ»è¡¨âã
3.æAlt+F11è¿å
¥VBA代ç ç¼è¾åè°è¯çé¢ã
4.æ ¹æ®ä¸å¾æ示ï¼æå
¥ä¸ä¸ªæ¨¡åã
5.å°ä¸è¿°ä»£ç ç²è´´å°æ¨¡å空ç½å¤ï¼
Sub CombineSheetsCells()
Dim wsNewWorksheet As Worksheet
Dim cel As Range
Dim DataSource, RowTitle, ColumnTitle, SourceDataRows, SourceDataColumns As Variant
Dim TitleRow, TitleColumn As Range
Dim Num As Integer
Dim DataRows As Long
DataRows = 1
Dim TitleArr()
Dim Choice
Dim MyName$, MyFileName$, ActiveSheetName$, AddressAll$, AddressRow$, AddressColumn$, FileDir$, DataSheet$, myDelimiter$
Dim n, i
n = 1
i = 1
Application.DisplayAlerts = False
Worksheets("å并æ±æ»è¡¨").Delete
Set wsNewWorksheet = Worksheets.Add(, after:=Worksheets(Worksheets.Count))
wsNewWorksheet.Name = "å并æ±æ»è¡¨"
MyFileName = Application.GetOpenFilename("Excelå·¥ä½è (*.xls*),*.xls*")
If MyFileName = "False" Then
MsgBox "没æéæ©æ件ï¼è¯·éæ°éæ©ä¸ä¸ªè¢«å并æ件ï¼", vbInformation, "åæ¶"
Else
Workbooks.Open Filename:=MyFileName
Num = ActiveWorkbook.Sheets.Count
MyName = ActiveWorkbook.Name
Set DataSource = Application.InputBox(prompt:="请éæ©è¦å并çæ°æ®åºåï¼", Type:=8)
AddressAll = DataSource.Address
ActiveWorkbook.ActiveSheet.Range(AddressAll).Select
SourceDataRows = Selection.Rows.Count
SourceDataColumns = Selection.Columns.Count
Application.ScreenUpdating = False
Application.EnableEvents = False
For i = 1 To Num
ActiveWorkbook.Sheets(i).Activate
ActiveWorkbook.Sheets(i).Range(AddressAll).Select
Selection.Copy
ActiveSheetName = ActiveWorkbook.ActiveSheet.Name
Workbooks(ThisWorkbook.Name).Activate
ActiveWorkbook.Sheets("å并æ±æ»è¡¨").Select
ActiveWorkbook.Sheets("å并æ±æ»è¡¨").Range("A" & DataRows).Value = ActiveSheetName
ActiveWorkbook.Sheets("å并æ±æ»è¡¨").Range(Cells(DataRows, 2), Cells(DataRows, 2)).Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _
SkipBlanks:=False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
DataRows = DataRows + SourceDataRows
Workbooks(MyName).Activate
Next i
Application.ScreenUpdating = True
Application.EnableEvents = True
End If
Workbooks(MyName).Close
End Sub
6.å¨âé¦é¡µâå·¥ä½è¡¨ä¸æä¸å¾ç¤ºèæå
¥ä¸ä¸ªçªä½æ§ä»¶å¹¶æå®å®ä¸ºæå
¥ç代ç å称ã
7.ç¹å»âé¦é¡µâå·¥ä½è¡¨ä¸æå
¥çæé®ï¼æ ¹æ®æ示ï¼æµè§å°åå§æ°æ®å·¥ä½ç°¿ã
8.ä¸ä¸æ¥ï¼ç¨é¼ æ éæ©è¦å并çæ°æ®èå´ã
注æï¼æ¯ä¸ªå·¥ä½è¡¨æ°æ®å¯è½ä¸ä¸æ ·ï¼æ¯å¦è¯´æçæ¯10è¡æ°æ®ï¼æçæ¯30è¡æ°æ®ãå¨è¿éå¯ä»¥ç¨é¼ æ éæ©ä»»æå·¥ä½è¡¨çä¸ä¸ªè¾å¤§èå´ï¼æ¯å¦è¯´A1:D100ï¼ä¿è¯æ¯æå¤è¡æ°çå·¥ä½è¡¨æ°æ®è¿å¤å°±å¯ä»¥ï¼ä¸ä¼åå é¤ç©ºè¡ã
9.ç¹å»ç¡®å®æé®ï¼å¾
代ç è¿è¡å®æ¯åï¼ææçæ°æ®å°±é½å并å°äºâå并æ±æ»è¡¨âä¸ã
注æï¼
1ï¼Aåçææ¬è¯´æå³ä¾§çæ°æ®æ¥èªäºåå§æ°æ®è¡¨çåªä¸ªå·¥ä½è¡¨ï¼
2ï¼æ°æ®ä¹é´ä¼æä¸äºç©ºè¡ï¼ä¸é¢éè¿çéå é¤ã
10.éä¸å
¨é¨æ°æ®åºåï¼æ§è¡èªå¨çéãç¶åéæ©å
¶ä¸ä¸ä¸ªå段ï¼éæ©â空ç½âåæ é¢å
容ã
11.ç¶åå°çéåºæ¥çæ ç¨è¡é¼ æ å³é®å é¤ï¼åå é¤Aåæ´åå³å¯ï¼å®æææå¦ä¸å¾ï¼
温馨提示:内容为网友见解,仅供参考