VBA select range of cells containing formula with value based on first column

ADingy1

New Member
Joined
Mar 18, 2018
Messages
6
I have a spreadsheet used to create a file template for another program. Below is an example of my sheet. The data set is in columns A though H and rows 1 through 51. Based on the criteria from other sheets, the rows will be filled top down. Columns A:C will only fill if the appropriate selections have been made using data validation on other worrksheets, but D though H will always contain a value. I need a way to select columns A:H but only the rows that contain data in columns A:C. In the example below, I would want to select $A$1:$H$4. Thank you all for your help.
ABCDEFGH
1"U.S."3337038040013017562.1 psi
2.5.8.25036032345
3.25.9.153234542344
4.5.85.24234465310
56531065-520
665-52065-520

<tbody>
</tbody>

****** id="cke_pastebin" style="position: absolute; top: 118px; width: 1px; height: 1px; overflow: hidden; left: -1000px;">
.1.25.2

<tbody>
</tbody>
</body>
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Hi & welcome to MrExcel
How about
Code:
Sub chk()
   Dim UsdRws As Long
   UsdRws = Range("A:A").find("*", , xlValues, , , xlPrevious, , , False).Row
   Range("A1:H" & UsdRws).Select
End Sub
 
Upvote 0
Hi & welcome to MrExcel
How about
Code:
Sub chk()
   Dim UsdRws As Long
   UsdRws = Range("A:A").find("*", , xlValues, , , xlPrevious, , , False).Row
   Range("A1:H" & UsdRws).Select
End Sub
It is selecting all cells in A1:H. I think UsdRws is either reading the lower rows because the last set of 4 cells in them are used or it is looking at the formula they contain.
 
Upvote 0
Ok, how about
Code:
Sub chk()
   Dim UsdRws As Long
   UsdRws = Range("A:A").find("", , xlValues, , , xlNext, , , False).Row
   Range("A1:H" & UsdRws - 1).Select
End Sub
 
Upvote 0
Thanks for the fast responses but again no dice. I looked at the original code you posted again and it is selecting A1:H52, however Row 52 contains no data. The new code is selecting A1:H51. Looking at it, it seems like it should have only selected A1:H50, so I'm not sure what's going on. With A1:A51 containing the formulas A1='Sheet 3'!C60 and A2='Sheet 3'!C63 to A51='Sheet 3'!C112 I don't know why Row 52 is being selected in the first place though. If you could give me a very quick understanding of why I would appreciate it as well. I've learned what I know about VBA from reading the macros I record so I know that I'm severely lacking knowledge. Thanks for the response again.
 
Upvote 0
This line
Code:
UsdRws = Range("A:A").find("", , xlValues, , , xlNext, , , False).Row
should find the 1st cell in col A that has no value & assigns that row number to UsdRws.
As you don't want to select that row, the next line UsdRws -1, which should then select the correct range.
What is in C112 on sheet 3? If it looks blank, check that there isn't a space in there
 
Upvote 0
My referenced cells on sheet 3 reference other cells on sheet 3 which combine information from sheet 2 and sheet 9 based on input information from sheet 1 using an intermediary table (the one my reference cells look at on sheet 3) and then perform some basic operations. I'm stepping it though a number of sheets because I thought I would be the only one using it, but now I'm trying to automate it. I might be able to remove my reference table and change my references to sheet based, but I'm not sure if that will help though, since ultimately it all points back to an input sheet.
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,978
Messages
6,122,545
Members
449,089
Latest member
davidcom

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