vba - 自动填充到特定日期
问题描述
我正在使用日期数据并希望自动填充到特定日期。具体日期将存储为 value X
。X
是列中的最后一个值A
我在 StackOverflow 上查看了其他一些帖子,但我一直遇到的问题是设置我的最终“价值”。我的最终价值不会是一个数字,而是一个停止的日期。
With ThisWorkbook.Sheets("Form Date 2")
'Select this workbook
Dim X as Date
'I am not sure what I need to Dim this as
Range("B2").Value = Range("A2").Value
'B2 is the value I want to autofill down with
X = Range("A" & Rows.Count).End(xlUp).Value
'X will be the last value in column A
Range("B2").Autofill Destination:=Range("B2:B" & X), Type:=xlFillSeries
'Not sure what to set my Type as
End With
所以最终的结果是, ColumnB
将获得从A1
到最后一个值的所有日期A
(02/04/2018-05/06/2018)
。格式应为 dd/mm/yyyy。
在 ColumnA
我有一大堆日期,但有些丢失了,所以我也抓住了所有丢失的日期。
有了下面的图片,我就有了Dates
专栏。我希望 VBA 吐出该All Dates
列。因此,代码将复制并粘贴A2
到B2
然后自动填充,直到列A
(不是行)中的最后一个值。所以在这个例子中All Dates
应该继续向下直到 value/date 01/06/2018
。
解决方案
也许这会起作用:
With ThisWorkbook.Sheets("Sheet2")
'Select this workbook
Dim X As Integer
'I am not sure what I need to Dim this as
.Range("B2").Value = .Range("A2").Value
'B2 is the value I want to autofill down with
X = .Range("A" & .Rows.Count).End(xlUp).Row
'X will be the last value in column A
.Range("B2").Select
Selection.AutoFill Destination:=.Range("B2:B" & X), Type:=xlFillDefault
'Not sure what to set my Type as
End With
更新代码以填写 A 列最后一个单元格的日期:
With ThisWorkbook.Sheets("Sheet2")
'Select this workbook
Dim X As Integer
'I am not sure what I need to Dim this as
.Range("B2").Value = .Range("A2").Value
'B2 is the value I want to autofill down with
X = .Range("A" & .Range("A" & .Rows.Count).End(xlUp).Row).Value - .Range("B2").Value
'X will be the last value in column A
.Range("B2").Select
Selection.AutoFill Destination:=.Range("B2:B" & X + 2), Type:=xlFillDefault
'Not sure what to set my Type as
End With
推荐阅读
- rstudio - 如何更改 RStudio 脚本选项卡中的字体大小?
- r - 使用空单元格抓取 PDF 表格
- javascript - 从 MongoDb 数据库中检索数据
- javascript - 我只想使用 ajax 将 textarea 条目作为帖子发送
- delphi - 如何在 EXE 中另一个 TForm 的 TPanel 中嵌入在运行时嵌入的 DLL 中的 TForm 上的控件,并获得正确的 Tab 键顺序?
- swift - 未定义符号 RealmSwift:“_OBJC_CLASS_$_RLMNotificationToken”,clang 错误
- sql - SSRS 报告超时
- uiview - 内容更改后需要 MKAnnotationView 的 detailCalloutAccessoryView 调整大小
- java - Android graphView没有动态更新
- java - Android 对话窗口。应用程序崩溃