こんにちは私はvbaを初めて使い、この仕事をするために一日中検索してきました。とにかく、 "EX"> 0の隣接セルの場合はEPの値を調整し、 "EX"の隣接セルの値が0の場合は空白または値を0に変更するために、 "EW"列内のすべてのセルに影響を与えるGoalSeekマクロが必要です"= 0.列" EP "" EW "と" EX "はすべて互いに影響し合います。以下は、私が一緒に掻き集めたコードです。あなたが書く必要があるテキスト値が0の場合はExcel VBA、それ以外の場合はゴールシーク
Application.DisplayAlerts = True
Application.ScreenUpdating = True
前に任意のヘルプ
Private Sub CommandButton1_Click()
Dim StartTime As Double
Dim MinutesElapsed As String
'Remember time when macro starts
StartTime = Timer
Dim lr As Long
Dim cell As Variant
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Range("A9").Select
lr = Cells.Find("*", SearchORder:=xlByRows, SearchDirection:=xlPrevious).Row
For j = 9 To lr
If Cells(j, "EX").Value > 0 Then
Cells(j, "EP").GoalSeek Goal:=60, ChangingCell:=Cells(j, "EW")
For Each cell In Range("EW9:EW" & lr)
cell.Value = WorksheetFunction.Round(cell.Value, 0)
Next cell
Application.DisplayAlerts = True
Application.ScreenUpdating = True
'Determine how many seconds code took to run
MinutesElapsed = Format((Timer - StartTime)/86400, "hh:mm:ss")
'Notify user in seconds
MsgBox "This code ran successfully in " & MinutesElapsed & " minutes", vbInformation
End Sub