Using Excel 2007 and inexperienced with VBA.
I am trying to create a text generator where, given a particular type of entry, it returns a string of text AND a number of corresponding cells.
I have a lot of data to combine and somewhat complex text statements. The data I have here is sample data. The final file will combine multiple text strings ("one" and "two", etc) with multiple cells that need to be referenced based on the specific data input there (some instances require 8 different cells).
I was able to figure out how to do Select Case where it can look up the type of entry I need, and it returns a specific text string. Great! I also know I can combine things like "One" & "Two". But how do I combine the corresponding text for the line?
Where if the entry was "ID" I could return something that looked like "One 1" but combines "One " & K2 as the .Value to return?
Image shows the sample data
Image shows data for Columns I, J, and K. Column I stores the entry type, J is where the data is returned, and K is the column with data to be referenced. Again, what's here is the simplified reference data.
I know this line is wrong. But I'm not sure what to put in place for K2 so it will correctly reference the cell, and then loop correctly for 300 times.
Case Is = "ID": .Value = "One" & (K2)
Am I close to something workable? What would you suggest? Is Select Case the wrong way to handle this problem?
I've tried a number of options, but I am inexperienced with VBA. I think whatever I implemented to fix the issue was likely done incorrectly.
Full code of what I have shown below.
Private Sub CommandButton1_Click()
Dim logtype As Range
For Each logtype In Range("I2:I302")
With logtype.Offset(0, 1)
Select Case logtype.Value
Case Is = "ID": .Value = "One" & K2
Case Is = "Phase": .Value = "Two"
Case Is = "Install New": .Value = "Three"
Case Is = "Install OH": .Value = "Four"
Case Is = "Install AR": .Value = "Five"
Case Is = "Insp": .Value = "Six"
Case Is = "LUI": .Value = "Seven"
Case Is = "": .Value = ""
Case Else: .Value = "Not Recognized"
End Select
End With
Next logtype
End Sub
EDIT:
What I put in a comment below, just formatted more clearly.
I want to create a macro that spits out the correct language of an entry based on the kind of work completed in a work order.
For example, ID or Install New and then return the correct language and reference data for the entry:
I2: ID
K2: Number (I'd type in the actual No.)
Returns:
"Complied with ID No. [K2]. No defects noted."
I4: Install New
L4: Actual part number
M4: etc...
N4: ...
O4: ...
Returns:
"Removed P/N [L4], S/N [M4]. Installed P/N [N4], S/N [O4]. Ops checked good."
Does that make sense? Thanks!
EDIT 2:
Hey everyone, I've tried tracking down alternative methods of solving this problem but I still haven't produced anything better than what I have here.
Any thoughts or help would be greatly appreciated. Thank you!