Referencing Multiple Cells Within A Loop (VBA)

daveh21

New Member
Joined
May 29, 2015
Messages
3
Hi guys,
Think this is a relatively simple fix, but have not come across the solution online yet, so apologies if I have missed something obvious!
I am looking at labeling each variable in a loop.
So we have a very basic table, such as :
<code style="font-family: monospace, monospace; margin: 0px 2px; border: 0px; border-radius: 2px; word-break: normal; display: block; font-size: 1em; line-height: 1.42857142857143em; padding: 0px !important; background-color: transparent;"> A B C (just uses a Countif formula in here fyi)

London London1

London London2


London London3
</code>With this VBA code for it:
<code style="font-family: monospace, monospace; margin: 0px 2px; border: 0px; border-radius: 2px; word-break: normal; display: block; font-size: 1em; line-height: 1.42857142857143em; padding: 0px !important; background-color: transparent;">Sub TEST()
LDN_Count= Application.WorksheetFunction.CountIf(Sheets("Sheet1").Range("B1:B10"), "London")
Dim i As Integer
For i = 1 To LDN_Count
"LDN_Locations_"&i = Application.WorksheetFunction.Match("London" & i, Sheets("Sheet1").Range("C1:C10"), 0)
Next i
End Sub
</code>The incorrect part is "LDN_Locations_"&i, but do not know how to label this without generating an error so that I can have a list of locations, I.e. LDN_Location_1 = 2, LDN_Location_2 = 4, LDN_Location = 7... So that I can use them later on in the code.
Any help much appreciated!! Thanks!
 

Forum statistics

Threads
1,082,298
Messages
5,364,375
Members
400,793
Latest member
hamzayagiz

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top