【发布时间】:2017-09-03 23:44:51
【问题描述】:
我试图将一年添加到它添加到列中的任何值。我不想粘贴到新列,而是替换同一列上的值。
目前我写的代码是:
Private Sub Update_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim path As String, fileName As String
Dim lastRowInput As Long, lastRowOutput As Long, rowCntr As Long, lastColumn As Long
Dim inputWS1 As Worksheet, outputWS As Worksheet
Set inputWS1 = ThisWorkbook.Sheets("Universal")
Set outputWS = ThisWorkbook.Sheets("Carriers")
rowCntr = 1
lastRowInput = inputWS1.Cells(Rows.Count, "A").End(xlUp).Row
lastRowOutput = outputWS.Cells(Rows.Count, "A").End(xlUp).Row
lastColumn = inputWS1.Cells(1, Columns.Count).End(xlToLeft).Column
inputWS1.Range("A4:A" & lastRowInput).Copy outputWS.Range("B2")
inputWS1.Range("B4:B" & lastRowInput).Copy outputWS.Range("C2")
outputWS.Range("E2:E" & (lastRowInput - 2)).Value = inputWS1.Name
inputWS1.Range("J4:J" & lastRowInput).Copy outputWS.Range("G2")
inputWS1.Range("G2:G" & lastRowInput).Value = DateAdd("yyyy", -1, CDate(inputWS1.Range("G2:G" & lastRowInput)))
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
我需要你们帮助我的是:
DateAdd("yyyy", -1, CDate(inputWS1.Range("G2:G" & lastRowInput)))
其中 inputWS1 是我的工作表的名称,lastrowinput 是我的变量,用于查找列上的最后一行。在我放置此代码时,G2 上已经有值,我只想将它们转换为它们所在列上的去年日期。
请帮忙
【问题讨论】:
-
您希望在单击按钮时为一列单元格添加年份。 ...您计划单击该按钮多少次?
-
其实一个月一次,因为按钮会在单元格中导入新数据。然而,它只是用前一个单元格中的数据覆盖旧数据。所以基本上每次我点击按钮时,它都会清除新工作表上的所有内容并从旧工作表中复制它。
-
您应该提到您正在删除工作表内容。我试图找出一种机制,在多个宏运行中只更新一次一年
-
道歉。这是一份每月从几张纸中获取信息的文件。这些工作表上的信息不会被删除,因此运行宏的文档每个月都会重新获取所有信息。