指定不被 VBA 宏编辑的数据/列范围

问题描述

我有一组数据,用于为分销公司创建路线表。宏提取每个具有特定路线代码的数据,然后为找到的每个路线代码创建一个新的 Excel 表,然后将数据移动到每个相应的路线代码表。但是,在创建的路线表上,它正在编辑整个工作表,即使我指定的范围为:Range("A8:E42").Select 我希望它跳过编辑范围为 ("F8:J42")

的任何手动输入的数据

我认为这是我需要更改代码的地方:

'Fill in information - Deliveries and RMAS
  '''  For i = 1 To Worksheets.Count
        If Left(Worksheets(i).Name,4) = "LOAD" And Right(Worksheets(i).Name,6) <> "MASTER" Then
            LoadSheet = Worksheets(i).Name
            Sheets(LoadSheet).Select
            Range("A8:E42").Select
            Selection.ClearContents
            'Fill in information - Deliveries
            For Each Cell In Sheets(Deliveries).Range("F2:F" & Full_Record_Count)
                If Cell.Value = Sheets(LoadSheet).Range("D4").Text Then
                    Sheets(LoadSheet).Range("A" & (8 + Counter)).Value = Sheets(Deliveries).Range("C" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("B" & (8 + Counter)).Value = Sheets(Deliveries).Range("I" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("C" & (8 + Counter)).Value = Sheets(Deliveries).Range("A" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("D" & (8 + Counter)).Value = Sheets(Deliveries).Range("L" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("E" & (8 + Counter)).Value = Sheets(Deliveries).Range("K" & Cell.Row()).Value
                    Counter = Counter + 1
                End If
            Next Cell'''

我的宏的完整代码如下:

Sub UpdateLoad_Click()

    'Set Variables
    Dim xWS As Worksheet
    
    Deliveries = ActiveSheet.Name
    RMA = "RMA-PICKUP"
    Counter = 0
    
    'Get the last row for loop
    Sheets(Deliveries).Activate
    Range("A1").Select
    Selection.End(xlDown).Select
    Full_Record_Count = ActiveCell.Row
    If Full_Record_Count = 1048576 Then
        Full_Record_Count = 3
    End If
    
    'Get the last row for loop
    Sheets(RMA).Activate
    Range("A1").Select
    Selection.End(xlDown).Select
    RMA_Record_Count = ActiveCell.Row
    If RMA_Record_Count = 1048576 Then
        RMA_Record_Count = 3
    End If
    
    'Delete Old Routes
    Sheets("Template DeFinitions").Activate
    Range("BA1:BA1000").Select
    Selection.ClearContents
    
    'Delete Older Sheets
    For Each xWS In Application.ActiveWorkbook.Worksheets
        If Left(xWS.Name,4) = "LOAD" And Right(xWS.Name,6) <> "MASTER" Then
            Application.displayAlerts = False
            xWS.Delete
            Application.displayAlerts = True
        ElseIf Left(xWS.Name,6) = "PALLET" And Right(xWS.Name,6) <> "MASTER" Then
            Application.displayAlerts = False
            xWS.Delete
            Application.displayAlerts = True
        Else

        End If
    Next xWS
    
    'Get list of Route Sheets Needed
    Sheets(Deliveries).Activate
    Sheets(Deliveries).Range("F2:F" & Full_Record_Count).Select
    Selection.copy
    Sheets("Template DeFinitions").Activate
    Range("BA1").Select
    ActiveSheet.Paste
    
    Range("BA1").Select
    Selection.End(xlDown).Select
    Route_Record_Count = ActiveCell.Row
    If Route_Record_Count = 1048576 Then
        Route_Record_Count = 2
    End If

    ActiveSheet.Range("BA1:BA" & Route_Record_Count).RemoveDuplicates Columns:=Array(1),Header:=xlNo
    Range("BA1:BA" & Route_Record_Count).sort key1:=Range("BA1"),order1:=xlAscending,Header:=xlNo
    
    Range("BA1").Select
    Selection.End(xlDown).Select
    Route_Record_Count = ActiveCell.Row
    If Route_Record_Count = 1048576 Then
        Route_Record_Count = 1
    End If
    
    'Creating all needed sheets
    For Each Cell In Sheets("Template DeFinitions").Range("BA1:BA" & Route_Record_Count)
        Sheets("LOAD MASTER").copy After:=Sheets(Sheets.Count)
        Worksheets("LOAD MASTER (2)").Activate
        ActiveSheet.Name = "LOAD " & Right(Cell.Value,6)
        Worksheets("LOAD " & Right(Cell.Value,6)).Visible = True
        Range("D4").Value = Cell.Value
        
        Sheets("PALLET MASTER").copy After:=Sheets(Sheets.Count)
        Worksheets("PALLET MASTER (2)").Activate
        ActiveSheet.Name = "PALLET " & Right(Cell.Value,6)
        Worksheets("PALLET " & Right(Cell.Value,6)).Visible = True
        Range("A1:JT22").Select
        Selection.Replace what:="LOAD MASTER",replacement:="LOAD " & Right(Cell.Value,6),lookat:=xlPart,MatchCase:=True
    Next Cell
    
    'Fill in information - Deliveries and RMAS
    For i = 1 To Worksheets.Count
        If Left(Worksheets(i).Name,6) <> "MASTER" Then
            LoadSheet = Worksheets(i).Name
            Sheets(LoadSheet).Select
            Range("A8:E42").Select
            Selection.ClearContents
            'Fill in information - Deliveries
            For Each Cell In Sheets(Deliveries).Range("F2:F" & Full_Record_Count)
                If Cell.Value = Sheets(LoadSheet).Range("D4").Text Then
                    Sheets(LoadSheet).Range("A" & (8 + Counter)).Value = Sheets(Deliveries).Range("C" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("B" & (8 + Counter)).Value = Sheets(Deliveries).Range("I" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("C" & (8 + Counter)).Value = Sheets(Deliveries).Range("A" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("D" & (8 + Counter)).Value = Sheets(Deliveries).Range("L" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("E" & (8 + Counter)).Value = Sheets(Deliveries).Range("K" & Cell.Row()).Value
                    Counter = Counter + 1
                End If
            Next Cell
            'Fill in information - RMAs
            For Each Cell In Sheets(RMA).Range("F2:F" & RMA_Record_Count)
                If Cell.Value = Sheets(LoadSheet).Range("D4").Text Then
                    Sheets(LoadSheet).Range("A" & (8 + Counter)).Value = Sheets(RMA).Range("C" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("B" & (8 + Counter)).Value = Sheets(RMA).Range("I" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("C" & (8 + Counter)).Value = Sheets(RMA).Range("A" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("D" & (8 + Counter)).Value = Sheets(RMA).Range("L" & Cell.Row()).Value
                    Sheets(LoadSheet).Range("E" & (8 + Counter)).Value = Sheets(RMA).Range("K" & Cell.Row()).Value
                    Counter = Counter + 1
                End If
            Next Cell
            Counter = 0
        End If
    Next i
    
    
    Sheets(Deliveries).Activate
    MsgBox ("Load and Pallet Sheets Completed")
    
End Sub

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...