# Adding a Max To Sum Formula - VBA



## Mark_Annonyous (Jan 3, 2023)

HI,

I hope everyone i staying clear of the storms that are hammering the U.S. ( for those of you who live there)

As the title suggests, i am looking for a push in the right direction to convert the below code into to something more binary. Rather than summing the result, i want a 1 or 0.

I've tried putting a application.max function but it just errors out.


```
For ColumnCounter = 5 To 1099
        Exportdate = alldata(1, ColumnCounter)
    For RowCounter = 2 To LastRowSummary
        ExShipCount = 0
        VesselName = alldata(RowCounter, 1) 'For each cell being evaluated, we need to store the Export country in column 1 to be evaluated.
       
        For DataImportCounter = 1 To LastRowDataImport
            If Reutdata(DataImportCounter, 29) = 1 Then
                If Reutdata(DataImportCounter, 1) = VesselName Then
                    If Exportdate >= Reutdata(DataImportCounter, 31) And Exportdate <= Reutdata(DataImportCounter, 32) Then
                      
                       ExShipCount = ExShipCount + 1

                    End If
                  End If
                End If
            
        Next DataImportCounter

         output1(RowCounter - 1, ColumnCounter - 4) = ExShipCount

    Next RowCounter
Next ColumnCounter

  Range(.Cells(2, 5), .Cells(LastRowSummary, 1099)) = output1
```


----------



## Mark_Annonyous (Jan 4, 2023)

Any help for a homey?


----------



## Joe4 (Jan 4, 2023)

I don't know if your question is quite clear without seeing what your data looks like.
You also appear to be using some UDFs for which you have NOT posted the VBA code (Reutdata and alldata).

I would recommend posting an example of the data you are working with along with your desired result so we can clearly see what you are working with and what you are trying to accomplish.

MrExcel has a tool called “XL2BB” that lets you post samples of your data that will allow us to copy/paste it to our Excel spreadsheets, so we can work with the same copy of data that you are. Instructions on using this tool can be found here: XL2BB Add-in

Note that there is also a "Test Here” forum on this board. This is a place where you can test using this tool (or any other posting techniques that you want to test) before trying to use those tools in your actual posts.


----------



## RoryA (Jan 4, 2023)

At a guess, you mean something like:


```
output1(RowCounter - 1, ColumnCounter - 4) = IIf(ExShipCount > 0, 1, 0)
```


----------

