English 中文(简体)
加入“VBA”的Excel公式和动态范围
原标题:Insert formula into Excel with VBA and a dynamic range
  • 时间:2024-01-28 00:52:59
  •  标签:
  • excel
  • vba

我有一些法典提出了我所需要的公式,我利用宏观记录器把填入最后一行。 但是,我如何能够妥善地加以规范,以便自动做到这一点,并将填补数据最后一行的公式? 我也试图删除某些发言,在试图插入公式时,就没有这样做了。

Sub RD_DS_InsertCol_Formula()
 
  RD_DS_InsertCol Macro
 

    With Sheets("Raw Data - DS")
        .Columns("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
    End With
    
    Range("G2").Select
    ActiveCell.FormulaR1C1 = _
        "=IF(RC[-1]=""Crossdock"",""CD"",IF(RC[-1]=""PickingPickedAtDestination"",""PP"",IF(RC[-1]=""PickingNotYetPickedPrioritized"",""PNYP"",IF(RC[-1]=""Loaded"",""LD,""""""))))"
    Range("G2").Select

    Selection.AutoFill Destination:=Range("G2:G14665"), Type:=xlFillDefault
    Range("G2:G14665").Select


End Sub
最佳回答

请审判。

Option Explicit

Sub RD_DS_InsertCol_Formula()
    With Sheets("Raw Data - DS")
        .Columns("C:C").Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        .Range("G2:G" & .Cells(.Rows.Count, "F").End(xlUp).Row).FormulaR1C1 = _
        "=IF(RC[-1]=""Crossdock"",""CD"",IF(RC[-1]=""PickingPickedAtDestination"",""PP"",IF(RC[-1]=""PickingNotYetPickedPrioritized"",""PNYP"",IF(RC[-1]=""Loaded"",""LD,""""""))))"
    End With
End Sub
问题回答

暂无回答




相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签