Excel VBA: Update Column G Based on Columns F, E, and I
Question details
Update values in column G using either the adjacent value in column F or specific conditions in columns E and I.

- Product
- Microsoft Excel
- Device & OS
- not provided
- Scenario
- A worksheet needs a VBA macro to update selected rows while leaving unrelated zeros and blank cells unchanged.
- Observed behavior
- A simple zero check can also match blank cells, and some zeros in column G must remain unchanged.
Confirm the worksheet name and that row 1 contains headers; the examples start at row 2. Save the workbook as an Excel Macro-Enabled Workbook (.xlsm) and enable macros if prompted.
Update Column G Using the sBin Rules
Use this macro for the clarified requirement: set column G to 1 or 2 only for matching column E and I values.
This macro matches an exact sBin value in column E, ignoring case and surrounding spaces. It updates qualifying rows regardless of their existing column G value and leaves all other rows unchanged.
The macro replaces any existing value or formula in column G on a qualifying row.
In Excel, press Alt+F11, then select Insert > Module.
Paste the following code into the module and replace Sheet1 with your worksheet name: Sub UpdateSBinRows() Dim ws As Worksheet Dim lastRow As Long, r As Long Dim eVal As Variant, iVal As Variant Set ws = ThisWorkbook.Worksheets("Sheet1") lastRow = ws.Cells(ws.Rows.Count, "E").End(xlUp).Row For r = 2 To lastRow eVal = ws.Cells(r, "E").Value iVal = ws.Cells(r, "I").Value If Not IsError(eVal) Then If StrComp(Trim$(CStr(eVal)), "sBin", vbTextCompare) = 0 Then If Not IsError(iVal) Then If IsNumeric(iVal) And Not IsEmpty(iVal) Then If Abs(CDbl(iVal) - 0.303) < 0.000000001 Then ws.Cells(r, "G").Value = 1 ElseIf Abs(CDbl(iVal) - 6.06) < 0.000000001 Then ws.Cells(r, "G").Value = 2 End If End If End If End If End If Next r End Sub
Return to Excel, press Alt+F8, select UpdateSBinRows, and click Run. Check the matching rows in column G.

Copy Column F to Nonblank Zero Cells in Column G
Use this alternative when every numeric zero in column G should be replaced by the adjacent value in column F.
Work with Excel Spreadsheets in WPS Office
WPS Office is a free, lightweight Office alternative with a familiar spreadsheet interface. Open compatible Excel files to review and edit worksheet data while keeping migration straightforward. Excel VBA support can vary by WPS edition and configuration.

Frequently Asked Questions
Why did my zero-check macro update blank cells?
In VBA, a blank cell can compare equal to zero. Check that the value is numeric and not blank before assigning a value, as in the copy macro above.
Does the sBin macro change every zero in column G?
No. It changes column G only when column E exactly matches sBin and column I is 0.303 or 6.06. It leaves other rows unchanged, including unrelated zeros.
Where do I change the worksheet name?
In the VBA editor, edit ThisWorkbook.Worksheets("Sheet1") and replace Sheet1 with the name shown on your worksheet tab.
Will the macros replace formulas in column G?
Yes, if a row meets the selected macro's conditions, the assignment to Cells(r, "G").Value replaces the existing formula with a value.




