Finding the Position of a Part Family Cell in Vba SolidWorks

Hello

I'm back on a macro and I'm changing my technique a bit so I'd like to have your help please.

I have a CAD file with a family of parts of about 30 configurations whose names are loaded into a list through a For loop so that the user can choose the one they need.
Each configuration represents diameter ranges of the same part: Config 1 = Part A with Ø0.1 - 1.0, Config 2 = Part A  with Ø 1.01 - 3.0, Config 3 = Part A with Ø3.01 - 10.0 etc. Using the UserFroms I created, the user can fill in the diameter in the range he has selected (being a parameter). Then I would like the value written in the dedicated textbox to go to the cell of the part family whose row is that of the chosen configuration and the column corresponding to the diameter parameter.
To do this, I need to find the position of the configuration cell, in reality the row is enough for me because I know that it is in column A and then shift to the right until I find the right column.

Explanation in pictures:

I'd like to know the line number of the red cell so I can write the value of the Ø in the green cell.

All this to say that I would like to find the position of a cell in VBA code please.
I hope I have been clear and thank you for your answers,

Have a nice day

Rub25

As its without testing just in my head I would loop on all lines and as soon as your previously chosen value match then you execute your code (I'm not a big fan of Excel search functions :!)

2 Likes

Hello

Since you told us what you're looking for, tell us what search criteria(s) you have...

Hello

In c# it could look something like this:

sheet = workbook.ActiveSheet;
int i = 1;
while (sheet.Cells(i, "A").value != "D03.97 - 8.99")
{
    i++;
}
MessageBox.Show("Ligne n° :" + i);

Kind regards

Hello

 

Like that,  very quickly and without being able to check, it seems to me that it would give something like this:

 

Diameter = InputBox("What diameter ?", "Choice of diameter", Diameter) 'Input box 

set found = columns("c"). Find(what:=Diameter, lookat:=xlWhole) 'Find the 'Diameter' value as an exact value (lookAt:=xlWhole) in column C
If Found Is Nothing Then' If Value Is Not Found

Msgbox "Diameter does not exist"

Else
   Row = Find.Row ' Returns the line number

End if

ActiveSheet.cells(row,"A") = activecells

 

Probably to tinker with a little, but it should help you a lot:)

Thank you all for your answers!

Indeed a simple While loop is enough to do what I asked thank you.

2 Likes

In Excel, there are the functions SEARCH, SEARCH, LOOKUP