VBA - 在一个范围内查找列位置

时间:2018-05-24 14:04:47

标签: vba excel-vba excel

我有一组连续的数据,比如A1:F10。

在B1中:F1是过去一周的日期。我的代码搜索昨天的日期,然后在右侧插入一列。在细胞A2:A10是果实的名称,其余细胞具有随机数量的果实。

我想要做的是循环播放Col A中的所有水果,如果水果是橙色,则在我插入到昨天日期右侧的列中输入一个值(比如1)。我可以定义的唯一范围是使用currentRegion的A1:F10和使用.find的wholeColumn的昨天的日期。

有没有人知道如何循环col A并在新插入的列中输入一个值(每次生成工作表时都可以在不同的位置)?我认为可以使用偏移量和列/单元格的某种组合来完成,使用第1行中昨天日期的单元格作为参考,因为空白列将始终位于此右侧。

提前致谢并对复杂的解释感到抱歉。

Dim myDate As Date

myDate = Application.InputBox("Please enter the date (DD/MM/YY)")

'Find yesterday's date in row 1

Rows("1:1").Select
Selection.Find(What:=myDate, After:=ActiveCell, LookIn:=xlFormulas _
    , LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False).Activate

Set Yesterday = ActiveCell

For Each mycell In range("A:A")

  If Left(mycell.Value, 4) = "Oran" Then

      mycell.Offset(0, Not sure what to put here).Value = 1

  End If

Next

不确定放在这里=我认为这与昨天变量+1有关但不太确定

0 个答案:

没有答案