简体   繁体   English

VBA如果Column(“ A”)。Cell(i).Value以“ x”开头,则Column(“ G”)。Cell(i).value =“ String”

[英]VBA if Column(“A”).Cell(i).Value begins with “x” then Column(“G”).Cell(i).value = “String”

How can I write this in VBA? 如何在VBA中编写此代码? I know it's a lot of criteria, but I tried to be thorough. 我知道这是很多标准,但是我努力做到透彻。

IF Cell.Value in Column "Job Number" (column "A") begins with (11*,12*,13*,14*) THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "AIRFRAME"

IF Cell.Value in Column "Job Number" (column "A") begins with "35W" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "WIRING"

IF Cell.Value in Column "Job Number" (column "A") begins with "34S" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "SOFTWARE"

IF Cell.Value in Column "Job Number" (column "A") begins with "32EB" OR "35EB" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "AVIONICS"

IF Cell.Value in Column "Job Number" (column "A") begins with "32EF" OR "35EF" BUT <> Cell.Value in Column "TEAM #" (column "H") = "Q3S251" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "AVIONICS"

IF Cell.Value in Column "Job Number" (column "A") begins with "23X" BUT <> Cell.Value in Column "TEAM #" (column "H") = "Q3S251" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "UTILITIES & SUBSYSTEMS"

IF Cell.Value in Column "TEAM #" (column "H") = "Q3S251" THEN cell.value in Column "TEAME NAME" (column "G").ROW(i) = "FUNCTIONAL TEST"

IF Cell.Value in Column "TEAME NAME" (column "G").ROW(i) = "PROPULSION" THEN Cell.Value = "UTILITIES"

Pretty much this is a code, which you can you to start: 这几乎是一个代码,您可以从中开始:

Option Explicit

Public Sub TestMe()

    Dim my_cell As Range

    Set my_cell = ActiveSheet.Cells(1, 1)

    Select Case True

        Case Left(my_cell, 3) = 11 Or Left(my_cell, 2) = 12:
            my_cell.Offset(0, 5) = "new value 11"
        Case Left(my_cell, 3) = "34S":
            my_cell.Offset(0, 5) = "new value 34S"
        Case Else:
            my_cell.Offset(0, 5) = "case else"
    End Select

End Sub

As a next step, make sure that you set my_cell correctly and make the conditions and the results the way you want them. 下一步,请确保正确设置my_cell并按照所需的方式设置条件和结果。 Enjoy! 请享用! :) :)

Sub ScrubSheets()

Dim lastRow As Long
Dim myRow As Long

Application.ScreenUpdating = False

'   Find last row in column A
lastRow = Cells(Rows.Count, "A").End(xlUp).Row

'   Loop for all cells in column A from rows 2 to last row
For myRow = 2 To lastRow
'       First check value of column G
    If Cells(myRow, "G") = "PROPULSION" Then
        Cells(myRow, "G") = "UTILITIES"
    Else
'           Then check column H
        If Cells(myRow, "H") = "Q3S2531" Then
            Cells(myRow, "G") = "FUNCTIONAL TEST"
        Else
 '               Check four character prefixes
            Select Case Left(Cells(myRow, "A"), 4)
                Case "32EB", "35EB", "32EF", "35EF"
                    Cells(myRow, "G") = "AVIONICS"
                Case Else
 '                       Check 3 character prefixes
                    Select Case Left(Cells(myRow, "A"), 3)
                        Case "35W"
                            Cells(myRow, "G") = "WIRING"
                        Case "34S"
                            Cells(myRow, "G") = "SOFTWARE"

                        Case Else
 '                               Check 2 character prefixes
                            Select Case Left(Cells(myRow, "A"), 2)
                                Case "11", "12", "13", "14"
                                    Cells(myRow, "G") = "AIRFRAME"
                             Case "23"
                                    Cells(myRow, "G") = "UTILITIES" & " & " & "SUBSYSTEMS"
                            End Select
                    End Select
            End Select
        End If
    End If
Next myRow

Application.ScreenUpdating = True

'   Message that macro is complete
    MsgBox "Macro complete!", vbOKOnly

End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 VBA *对于每个单元循环* IF(第1列中的值)= x AND IF(第2列中的等效值)&gt; 7 THEN - VBA *For Each Cell Loop* IF (Value in Column 1) = x AND IF (Equivalent Value In Column 2) >7 THEN VBA 将一列的单元格值以数值 (MMDD) 开头的数据行复制到另一个工作表 - VBA Copy rows of data where cell value of one column begins with numeric value (MMDD) to another worksheet VBA - 检查单元格值是否在列中 - VBA - Check if cell value is in a column 如何根据每个单元格的值和固定单元格的值有条件地格式化VBA中的列? - How do I conditionally format a column in VBA based on each cell's value and a fixed cell's value? 条件格式设置规则:X列中的单元格值以开头时突出显示行 - Conditional Formatting Rule: Highlight Row when Cell Value in X Column Begins With 如果单元格值为x,则删除列 - Deleteing column if the cell value is x 如何在距离我所在的单元格X列的单元格中写入(X是在另一个单元格中定义的值) - How can I write in a cell that is X number of column away from the cell I am on (X is a value defined in another cell) 如何在列中复制一个单元格数据,然后将其粘贴,直到另一个值通过 VBA 进入列中? - How can i copy one cell data in a column and then paste it untill another value comes in the column through VBA? Excel VBA-如果单元格以“ find”开头,则返回另一个单元格的值 - Excel VBA - If cell begins with “find” then return value of a different cell 特定列中所选单元格的VBA复制值 - VBA copy value of selected cell in specific column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM