如何在VBA中写这个?我知道这是很多标准,但我试图彻底。
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"
答案 0 :(得分:0)
这是一个代码,你可以开始:
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
下一步,请确保正确设置my_cell
,并按照您希望的方式制作条件和结果。请享用! :)
答案 1 :(得分:0)
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