VBA change cell values based on the text in one column and a number in another column

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Hi, I am very new to VBA. I need to modify some of the values in column D based on the text in K and the number in L.
We will use column K to determine the type of item, and use the number in L to determine which range this number falls in. It then pulls the correct item# from the master.xlsx and replaces the value in column D.
If the number in L falls in 12"-19", we will assign an item# for 12"; if it falls in 20-32, we will assign it item# for 24"; if it falls in 33"-42, we will assign the item# for 36"...etc
the excel file in the first screenshot is located on a company server, the master.xlsx is on another drive on company server (we can save this file locally if needed)
here is an example: In rows 2, 3, and 7 in screenshot 1, there are:
C BOX (6" WALL) with a height of 14", which is in the range of 12-19, we will need to assign cell D2 the item# F22122J from cell B36 in the master.xlsx file (screenshot 2)
D BOX (6" WALL) with a height of 26", which is in the range of 20-32, we will need to assign cell D3 the item# F22133J from cell B101 in the master.xlsx file (screenshot 3)
C BOX (6" WALL) with a height of 20", which is in the range of 20-32, we will need to assign cell D7 the item# F22123J from cell B37 in the master.xlsx file (screenshot 4)
Any help is greatly appreciated !

1641347396582-png.54437


1641347865090.png

1641348094513.png

1641348214953.png
 

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Just to clarify Zack, is the sole ultimate objective here to get the correct item# from the master & put it into column D of the latest .csv file - or does the height from column L of the .csv also need to be appended to the description in column K (or was this just an intermediate step in the process)? Also, you say the numbers in column L can be as high as 96 - have you listed the complete range of possibilities in the master (12-72) in your screen shot? If not, I'll need all of them (numbers only - not text). Also, would there be an issue if you house the code in the master file?
If there are too many issues with having a master file, can I just use select case, and hard code all the item code into the macro? What is the major downside of using select case with a very long list?
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.

kevin9999

Board Regular
Joined
Aug 28, 2020
Messages
132
Office Version
  1. 365
Platform
  1. Windows
Thanks for all this.
OK Zack, I have a plan but I'm busy elsewhere for a while. One more piece would help, do all the items that require the number in column L added to them have a common word in their string? For example, from what I can tell, all items with "BOX" or "SAN" seem to need the number added, whereas all with "CHAIN" or "HOLE" don't? If this is so, could you give me a list of all that do - a single common word will suffice. Offline now for a while.
 

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
Thanks for all this.
OK Zack, I have a plan but I'm busy elsewhere for a while. One more piece would help, do all the items that require the number in column L added to them have a common word in their string? For example, from what I can tell, all items with "BOX" or "SAN" seem to need the number added, whereas all with "CHAIN" or "HOLE" don't? If this is so, could you give me a list of all that do - a single common word will suffice. Offline now for a while.
here is a list, these are all the ones I can think of for now. Anything contain these words need to be modified:

Box
Base
Riser
Collar
 

kevin9999

Board Regular
Joined
Aug 28, 2020
Messages
132
Office Version
  1. 365
Platform
  1. Windows
Hi Zack, I'm afraid this is a bit beyond me. As far as adding the height suffixes to the end of the descriptions - not a problem. The following code is an upgrade of what I provided earlier:

VBA Code:
For Each c In rng
        If c Like "*BOX*" Or _
            c Like "*BASE*" Or _
            c Like "*RISER*" Or _
            c Like "*COLLAR*" Then
                c = c & " " & c.Offset(, 1)
        End If
    Next

When it comes to determining which 'range' the different items fall into - again, not a problem:

VBA Code:
x = Application.WorksheetFunction.Floor(Val(c.Offset(, 1)), 12)

where 'x' is the rounded down number to the nearest factor of 12 (seems to be how they're classified)

The problems start when it comes to comparing the text parts of the descriptions in the csv with the corresponding strings in the master file. They are significantly different in their format/arrangement, and I can't figure out a way to reconcile this. Sorry Zack, I did try :confused:
 

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

Hi Zack, I'm afraid this is a bit beyond me. As far as adding the height suffixes to the end of the descriptions - not a problem. The following code is an upgrade of what I provided earlier:

VBA Code:
For Each c In rng
        If c Like "*BOX*" Or _
            c Like "*BASE*" Or _
            c Like "*RISER*" Or _
            c Like "*COLLAR*" Then
                c = c & " " & c.Offset(, 1)
        End If
    Next

When it comes to determining which 'range' the different items fall into - again, not a problem:

VBA Code:
x = Application.WorksheetFunction.Floor(Val(c.Offset(, 1)), 12)

where 'x' is the rounded down number to the nearest factor of 12 (seems to be how they're classified)

The problems start when it comes to comparing the text parts of the descriptions in the csv with the corresponding strings in the master file. They are significantly different in their format/arrangement, and I can't figure out a way to reconcile this. Sorry Zack, I did try :confused:
Kevin, I am actually fixing the format of the description in the csv file, all the text will exactly match what is in the master file, like shown below
Sorry I guess I did not mention that
1641429973426.png
 

kevin9999

Board Regular
Joined
Aug 28, 2020
Messages
132
Office Version
  1. 365
Platform
  1. Windows
If that's the case, then it should be possible - but I'd need to see the changed format.
 

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

If that's the case, then it should be possible - but I'd need to see the changed format.
here are some screenshots of the format:
1641430959426.png
 

zack8576

New Member
Joined
Dec 27, 2021
Messages
41
Office Version
  1. 365
Platform
  1. Windows
If that's the case, then it should be possible - but I'd need to see the changed format.
and all the MH will follow this format, few more examples:
MH,4'dia,Base,24"
MH,4'dia,Riser,36"
MH,5'dia,Base,36"
MH,5'dia,Riser,36"
MH,5'dia,Riser,60"
1641431134093.png
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,151,962
Messages
5,767,350
Members
425,405
Latest member
jaskimo

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
Top