Was trying to do with a small lookup table (If = 20, then go find 20 in Col N and paste formula found inadjacent cell of Col O) but gave up on that route..
Found the BELOW might be a better/hard coded way to do it -- just not sure how to change the "Interior.Color" action to a Paste this formula INSTEAD action..
Example:........ IF oCell (which would be B2) = "14" Then PASTE THIS FORMULA into adjacent Col K =MID(B2,6,5)
............................ELSE...........see if that cell is = to "15".................if this is true, paste a different formula... =MID(B2,7,5)
............................ELSE...........see if it's = to ..............."16".................if this is true, paste a different formula... =MID(B2,8,5)
............................ELSE...........see if it's = to ..............."17".................if this is true, paste a different formula... =MID(B2,9,5)
............................ELSE...........see if it's = to ..............."18".................if this is true, paste a different formula... =MID(B2,10,5)
............................ELSE...........see if it's = to ..............."19".................if this is true, paste a different formula... =MID(B2,11,5)
............................ELSE...........see if it's = to ..............."20".................if this is true, paste a different formula... =MID(B2,12,5)
............................ELSE...........see if it's = to ..............."21".................if this is true, paste a different formula... =MID(B2,13,5)
............................ELSE...........see if it's = to ..............."22".................if this is true, paste a different formula... =MID(B2,14,5)
Once it finds a match and pastes it's appropriate formula to use, move to next cell... and adjust formula cell reference to be adjacent
In other words, I need to use B2 in the formula IF on row 2, .......use B3 within the formula if on row 3
I don't want a formula that looks like this to happen on row 10 (B10): =MID(B2,5,6)
Instead the formula on row 10 (B10) should look like this: ......................... =MID(B10,5,6)
....(next cell).....IF oCell (which would be B3) = "21" Then PASTE THIS FORMULA into adjacent Col K =MID(B3,13,5)
Here's what I thought might work well but not sure how to adjust it to paste various formulas instead of colorizing)
Thank you in advance!
Found the BELOW might be a better/hard coded way to do it -- just not sure how to change the "Interior.Color" action to a Paste this formula INSTEAD action..
- Col A has varied filenames with diff lengths..
- Col B has a LEN formula in it that provides the length (anywhere from 14 to 22 so far)
- Col K is where I want to paste a formula that will be specific if the LEN is 14, a different formula if the LEN is 15, etc)
Example:........ IF oCell (which would be B2) = "14" Then PASTE THIS FORMULA into adjacent Col K =MID(B2,6,5)
............................ELSE...........see if that cell is = to "15".................if this is true, paste a different formula... =MID(B2,7,5)
............................ELSE...........see if it's = to ..............."16".................if this is true, paste a different formula... =MID(B2,8,5)
............................ELSE...........see if it's = to ..............."17".................if this is true, paste a different formula... =MID(B2,9,5)
............................ELSE...........see if it's = to ..............."18".................if this is true, paste a different formula... =MID(B2,10,5)
............................ELSE...........see if it's = to ..............."19".................if this is true, paste a different formula... =MID(B2,11,5)
............................ELSE...........see if it's = to ..............."20".................if this is true, paste a different formula... =MID(B2,12,5)
............................ELSE...........see if it's = to ..............."21".................if this is true, paste a different formula... =MID(B2,13,5)
............................ELSE...........see if it's = to ..............."22".................if this is true, paste a different formula... =MID(B2,14,5)
Once it finds a match and pastes it's appropriate formula to use, move to next cell... and adjust formula cell reference to be adjacent
In other words, I need to use B2 in the formula IF on row 2, .......use B3 within the formula if on row 3
I don't want a formula that looks like this to happen on row 10 (B10): =MID(B2,5,6)
Instead the formula on row 10 (B10) should look like this: ......................... =MID(B10,5,6)
....(next cell).....IF oCell (which would be B3) = "21" Then PASTE THIS FORMULA into adjacent Col K =MID(B3,13,5)
Here's what I thought might work well but not sure how to adjust it to paste various formulas instead of colorizing)
VBA Code:
Sub Range_LoopCells()
Dim oRange As Range
Dim oCell As Range
Set oRange = Sheets(1).Range("B2:B365")
For Each oCell In oRange
If oCell = "14" Then oCell.Interior.Color = vbRed
If oCell = "15" Then oCell.Interior.Color = vbGreen
If oCell = "16" Then oCell.Interior.Color = vbYellow
If oCell = "17" Then oCell.Interior.Color = vbGreen
If oCell = "18" Then oCell.Interior.Color = vbRed
If oCell = "19" Then oCell.Interior.Color = vbGreen
If oCell = "20" Then oCell.Interior.Color = vbGreen
If oCell = "21" Then oCell.Interior.Color = vbGreen
If oCell = "22" Then oCell.Interior.Color = vbRed
Next oCell
End Sub
Thank you in advance!