Select Cell in Column based on Search Parameters

Vanish29

New Member
Joined
Apr 28, 2016
Messages
22
Good morning.
Full Explanation:
I am trying to create a header based on User Input, but inline with where the actual header is.
Ex: If User Input is Electricity, then macro searches for Electricity, then jumps down to the predetermined last row, based on a different column and outputs the User Input as a Value.

Code:
Dim Util1 As Variant
Dim Util2 As Variant
    Dim lastRow As Long
    lastRow = Range("B" & Rows.Count).End(xlUp).Row
Dim AC As Integer
AC = ActiveCell.Column
Util1 = InputBox("What is the first Utility that needs Redistribution? {Must match Header on Bill Summary}")
Util2 = InputBox("What is the second Utility that needs Redistribution? {Must match Header on Bill Summary}")
Range("J27").Value = Util2
    Cells.Find(What:=Util1, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=True).Activate
Range(AC & lastRow).Value = Util1

I was testing a few potential solutions, but no such luck. I believe the issue lies with the final line.
In the test data, the Search parameters find the User Input in Cell O2, and the lastrow would be 26.
Here is the snag: There is not contiguous data from O2 to O26, so a lastrow on Column O will place the User Input in the wrong location. Hence the need to base the lastrow on a different column. There will not be contiguous data for any other columns, except Column B.

If I am making this too hard on myself, please let me know.
 
I think I understand the confusion.
Please note that the User Form file only contains the userform, and still uses the Data File.

I think we have gotten too far off the issue, so let's swing back.
All I am trying to do is select the cell in a single column, using as lastrow as determined by a different column.

Example:
Column B has data down to Row 15. Column C has data down to row 5.
I want to activate C16.

In one of the earlier posts, you stated
I think that I have a solution up to step #5 . After that, I have some more questions. However, before we proceed, I think you have to decide whether or not you want to input the data with a userform or not. I don't want to waste your time or mine working on a solution that you may or may not use. If you want to use a userform, then create the form and upload an updated file with a description of what you want the form to do. If you want to proceed without the form, please let me know and I will ask for further clarification starting with step #6 .

I don't think the Userform would change how this is done. What was this potential solution?
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
I found it.

Here is the code
Code:
Sub Testing()
Dim lastRow As Long, Util1 As Variant
lastRow = Range("B" & Rows.Count).End(xlUp).Row
Util1 = "Water 2"
Cells.Find(What:=Util1, After:=ActiveCell, LookIn:=xlValues, LookAt:= _
        xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _
        , SearchFormat:=True).Activate
Cells(lastRow, ActiveCell.Column).Offset(2, 0).Value = Util1
End Sub

The issue was I was using the Range object, when I should have been using the Cells property.
The above code allows for the user defined value of Util1 to be entered in the same column as Util1 but 2 rows below the last used row of entire document.
Sorry for all the craziness.
Thank you for working with me on this.
 
Upvote 0

Forum statistics

Threads
1,215,156
Messages
6,123,339
Members
449,098
Latest member
thnirmitha

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