Listing All Possible Combinations

reberryjr

Well-known Member
Joined
Mar 16, 2017
Messages
714
Office Version
  1. 365
Platform
  1. Windows
I have what might be an odd question. I have a map that has even-sized plots within it. The latitude can range from 0 - 1200 and the longitude can range from 0 - 1200. I'm trying to list every single latitude & longitude combination possible (yes, I know it'll be a lot). How can I go about this?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
On an empty sheet.
Code:
Sub Maybe()
Dim i As Long, j As Long
ActiveSheet.Cells.NumberFormat = "@"
Application.ScreenUpdating = False
    For i = 0 To 1200
        For j = 0 To 1200
            Cells(j + 1, i + 1).Value = "Lat " & i & " - " & "Long " & j
        Next j
    Next i
Application.ScreenUpdating = True
End Sub
 
Upvote 0
On an empty sheet.
Code:
Sub Maybe()
Dim i As Long, j As Long
ActiveSheet.Cells.NumberFormat = "@"
Application.ScreenUpdating = False
    For i = 0 To 1200
        For j = 0 To 1200
            Cells(j + 1, i + 1).Value = "Lat " & i & " - " & "Long " & j
        Next j
    Next i
Application.ScreenUpdating = True
End Sub
Many thanks!
 
Upvote 0
This is about 4 times faster on my machine.
Code:
Sub With_Formula()
ActiveSheet.Cells.NumberFormat = "General"
Application.ScreenUpdating = False
With Range("A1:ATE1201")
    .Formula = "=""Lat "" & ROW()-1&"" - ""&""Long ""&COLUMN()-1"
    .Value = .Value
End With
Application.ScreenUpdating = True
End Sub
 
Upvote 0
A formula variant for modern Excel:

Excel Formula:
=SEQUENCE(1201,,0)&", "&SEQUENCE(,1201,0)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,246
Messages
6,170,987
Members
452,373
Latest member
TimReeks

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