简体   繁体   English

根据列表复制工作表和单元格值,并使用 excel vba 代码根据列表重命名

[英]copy sheet and cell value based on list and rename as per list with excel vba code

i am very new to vba, currently i am looking for code to copy cell values from list to multiple sheet in specific cell我对 vba 非常陌生,目前我正在寻找将单元格值从列表复制到特定单元格中的多个工作表的代码

what i am trying to do is as per bellow sheet "point" i have a list with values column B are the names and C & D are values我想做的是按照下面的表格“点”我有一个值列表 B 列是名称,C & D 是值

i need to copy sheet named "template" and rename as per the values in Column B and the values are un defined and be upto any length list sheet我需要复制名为“模板”的工作表并根据 B 列中的值重命名,并且这些值未定义并且可以达到任何长度的列表表

template模板

currently i am using bellow code to copy sheet and rename as per list目前我正在使用波纹管代码来复制工作表并根据列表重命名

Sub CopySheetRenameFromCell()

Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("template")
Set sh2 = Sheets("point")
For Each c In sh2.Range("B6", sh2.Cells(Rows.Count, 2).End(xlUp))
sh1.Copy After:=Sheets(Sheets.Count)
On Error Resume Next
ActiveSheet.Name = c.Value:
On Error GoTo 0
Next
End Sub

result sheet结果表

but i have no idea how can i copy value from "point" Sheet Column C and D values 1 & 51 to sheet "a" Column C2 and F2 and so on但我不知道如何将值从“点”表列 C 和 D 值 1 和 51 复制到表“a”列 C2 和 F2 等等

a values in sheet "a" b values in sheet "b" and on a 工作表“a”中的值 b 工作表“b”中的值及以上

awaiting your help等待你的帮助

Copy Template Worksheet复制模板工作表

  • This is a basic code.这是一个基本代码。 It assumes that each of the cells of the range B6:BLastRow contains a valid value for naming a worksheet.它假定范围B6:BLastRow的每个单元格都包含用于命名工作表的有效值。 It also assumes that each of the worksheets to be created does not exist already.它还假定要创建的每个工作表都不存在。
Option Explicit

Sub CopySheetRenameFromCell()

    ' Reference the workbook ('wb').
    Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
    
    ' Reference the source worksheet ('sws').
    Dim sws As Worksheet: Set sws = wb.Worksheets("Point")
    
    ' Calculate the source last row ('slRow'),
    ' the row of the last non-empty cell in the column.
    Dim slRow As Long
    slRow = sws.Cells(sws.Rows.Count, "B").End(xlUp).Row
    
    ' Reference the template worksheets ('tws').
    Dim tws As Worksheet: Set tws = wb.Worksheets("Template")
    
    ' Declare additional variables.
    Dim dws As Worksheet ' Current Destination (Copied) Worksheet
    Dim sr As Long ' Current Row in the Source Worksheet
    
    ' Loop through the rows of the source worksheet.
    For sr = 6 To slRow
         ' Create a copy of the template worksheet after the last sheet
         ' in the workbook.
         tws.Copy After:=wb.Sheets(wb.Sheets.Count)
         ' Reference this copy, the destination worksheet,
         ' which is the last (work)sheet in the workbook.
         Set dws = wb.Sheets(wb.Sheets.Count)
         ' Rename the destination worksheet.
         dws.Name = sws.Cells(sr, "B").Value
         ' Write the values from columns 'C' and 'D' in the row ('r')
         ' of the source worksheet to the cells `C2` and `F2` respectively
         ' in the destination worksheet.
         dws.Range("C2").Value = sws.Cells(sr, "C").Value
         dws.Range("F2").Value = sws.Cells(sr, "D").Value
    Next sr
    
    ' Save the workbook.
    'wb.Save
    
    ' Inform.
    MsgBox "Point worksheets created.", vbInformation
    
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Excel VBA 将工作表复制到新工作簿并重命名基于工作表的单元格值 - Excel VBA Copy sheet to new workbook with rename sheet based cell value Excel VBA代码将基于单元格引用的数据复制到另一个工作表 - Excel VBA Code to Copy Data based on a cell reference to another sheet VBA根据单元格值重命名工作表 - VBA rename sheet based on cell value 根据单元格值从可变工作表名称复制的 VBA 代码 - VBA code to copy from a variable sheet name based on cell value Excel VBA根据列表从多个工作表复制工作表数据 - Excel VBA copy sheet data from multiple sheets based on list Excel VBA比较单元格值以在单独的工作表中列出和覆盖值 - Excel VBA Compare cell value to list and overwrite value in separate sheet 如何使用 VBA 代码根据单元格值隐藏 Excel 表 - How to hide Excel Sheet based on cell value using VBA Code 如何使用 vba 根据 Excel 中另一张纸上的列表更改单元格的值? - How to change a cell's value using vba based off a list on another sheet in Excel? EXCEL VBA:查找代码以重命名具有指定名称的指定工作表,均基于单元格值 - EXCEL VBA: Looking for code to rename a specified sheet with specified name, both based on cell values excel VBA根据条件从列表(在另一个工作表中)选择一个值 - excel VBA select a value from a list (in another sheet) based on a condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM