Help with a code section that can find and select a range of cells from a list using values contained in other cells as start and end of range

lonesome_road_toad

New Member
Joined
Oct 26, 2021
Messages
4
Office Version
  1. 365
Platform
  1. Windows
Hi all!

I am working on my first macro that I've done from scratch with no recorded element. What I would like the macro to do ultimately is take an ID number (like "1234556677") and dilution range (think "1:2-1:64") that the user copy and pastes in and concatenate the ID number with only that range of dilutions (ID "1234556677" becomes "1234556677 1:2", "1234556677 1:4", "1234556677 1:8 etc) then copy and paste those contatenated IDs into a final list finding the last blank cell in the column to paste into as it goes through each ID in the list.

I made 2 functions that split the dilution range into the first dilution and last dilution in the range and puts them in to separate cells in columns T and U. Next to those columns in column V I have a list of the entire possible range of dilutions in order (1:2, 1:4, 1:8, 1:16, 1:32, etc). The piece I am having a hard time figuring out is how to use search the list for the first dilution (in the case below "1:8") and set that as the beginning of my range to be used, and then search the list for the last dilution ( "1:256" below) and use that as the end of the range, selecting all the cells in between them. I would like to loop this so that it will be performed for all the IDs pasted into column B by the user. Any ideas on where to begin/things I can look up to learn from would be much appreciated!

1635273702330.png
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
for reference this is where I am at, I want to build finding the last dilution, setting the range and concatenation into the loop before it ends as well

VBA Code:
'this section finds and stores the beginning and end of the dilution range in as it appears in column V'

Sub Find_First()
Dim FindString As String
Dim Rng As Range
For Each c In Range("T3:T40")
FindString = c
If Trim(FindString) <> "" Then
    With Sheets("Sheet1").Range("V:V") 'searches all of column V
        Set Rng = .Find(What:=FindString, _
                        After:=.Cells(.Cells.Count), _
                        LookIn:=xlValues, _
                        LookAt:=xlWhole, _
                        SearchOrder:=xlByRows, _
                        SearchDirection:=xlNext, _
                        MatchCase:=False)
        If Not Rng Is Nothing Then
            Application.Goto Rng, True 'first dilution found
            RngStart = Rng.Address
            MsgBox (RngStart)
            
        Else
            MsgBox "Dilution not found" 'dilution not found in list
        End If
        If c.Value = 0 Then Exit For
        
    End With
End If
Next c
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,245
Members
452,900
Latest member
LisaGo

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