ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Using contents of cells as input for variable? (https://www.excelbanter.com/excel-programming/390823-using-contents-cells-input-variable.html)

ble

Using contents of cells as input for variable?
 
Have code like below multiple times for strings (walls, diameter, etc.) which
exist as headers in a sheet of my workbook. How do I id those cell contents
as a variable in For Each to reduce the code to one time for each variable??
"walls" would be replaced (3) places by the correct variable, and for each
subsequent until empty??.

Thanks in advance for any help.

'walls

Sheets("CONVERT dat").Select
Cells(myRow, 1).Select
ActiveCell.FormulaR1C1 = "=HLOOKUP(""walls"",RC[1]:RC[100],1,FALSE)"
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
ActiveCell.Replace What:="#N/A", Replacement:="1", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ActiveCell.Replace What:="walls", Replacement:="2", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
If Selection = "2" Then
Cells(myRow, 2).Select
ActiveCell.EntireRow.Select
Cells.Find(What:="walls", After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(1, 0).Copy
Sheets("OUTPUT").Select
Cells(myRow2, 29).PasteSpecial
Else
Sheets("OUTPUT").Select
Cells(myRow2, 29).Select
ActiveCell.FormulaR1C1 = "N/A"
End If


All times are GMT +1. The time now is 05:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com