if statement

eramirez148

Board Regular
Joined
Aug 17, 2022
Messages
66
Office Version
  1. 365
  2. 2021
  3. 2019
  4. 2016
  5. 2013
  6. 2011
  7. 2010
Platform
  1. Windows
  2. MacOS
How can I get the results in column A. If a numerical value is visible in column B then I want this to appear in column A until the next text of order quantity appears.

AB
5280​
Quantity Ordered
5280​
5280​
5280
5280​
5280​
5280​
5280​
5280​
5280​
4920​
Quantity Ordered
4920​
4920​
4920
4920​
4920​
4920​
4920​
4920​
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Do you really have 7 differents version of Excel on both platforms? Which version are you actually using?
 
Upvote 0
Put this in the Sheet Module of your Sheet and run it. Remember to test on a COPY of your Workbook.
VBA Code:
Option Explicit

Sub addNum()

Dim myRng As Range, i As Long, cell As Range, lRow As Long, subRngs() As String, tStart As String, tEnd As String
Dim nbrs() As Long, x As Long, nbr

lRow = Me.UsedRange.Rows.Count
Set myRng = Me.Range(Cells(1, 2), Cells(lRow, 2))
For Each cell In myRng
    If cell.Row = lRow Then
        tEnd = cell.Address
        ReDim Preserve subRngs(i)
            subRngs(i) = Range(tStart & ":" & tEnd).Address
            tStart = cell.Address
            i = i + 1
    End If
    If WorksheetFunction.IsText(cell.Value) Then
        Select Case tStart
            Case Is <> Empty
                tEnd = cell.Offset(-1, 0).Address
            Case Is = ""
                tStart = cell.Address
        End Select
        If Not tStart = "" And Not tEnd = "" Then
            ReDim Preserve subRngs(i)
            subRngs(i) = Range(tStart & ":" & tEnd).Address
            tStart = cell.Address
            i = i + 1
        End If
    ElseIf WorksheetFunction.IsNumber(cell.Value) Then
        ReDim Preserve nbrs(x)
        nbrs(x) = cell.Value
        x = x + 1
    End If
Next cell
For i = 0 To UBound(subRngs)
    Range(subRngs(i)).Offset(0, -1) = nbrs(i)
Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,004
Messages
6,175,904
Members
452,682
Latest member
ghorne

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top