Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting Text In Front of String

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm writing an Excel macro to convert the format of the spreadsheet to a style that can be read by our MileMaker program (i.e. a batch report). I've got the cell manipulating set up just fine, and the loop to continue the program until the active cell is empty. The only problem I'm having is that I need to insert "OR" and "DT" in front of them. Here is the code for it as of now:

Sub change_before_do_loop()
Do Until IsEmpty(ActiveCell)
Selection.EntireRow.Insert
ActiveCell.Offset(2, 0).Range("A1").Select
Selection.EntireRow.Insert
ActiveCell.Offset(-1, 0).Range("A1").Select
Selection.Cut
ActiveCell.Offset(1, -2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-1, 3).Range("A1").Select
Selection.Cut
ActiveCell.Offset(1, -2).Range("A1").Select
ActiveSheet.Paste
ActiveCell.Offset(-2, -1).Range("A1").Select
ActiveCell.FormulaR1C1 = "HRMI"
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.TypeText Text:="OR"
ActiveCell.Offset(1, 0).Range("A1").Select
Selection.TypeText Text:="DT"
ActiveCell.Offset(1, 2).Range("A1").Select
Loop
End Sub

The Selection.TypeText, however, does not work correctly, giving me an error message stating that the object or method does not exist. Can anyone offer some help? I just need to know how to insert letters in front of strings, basically. The problem may be that "Selection" is not reading correctly as the variable, I don't know. Thanks,


Nathan
 
Hi,
Whatever cell is Selected that you want the Substitutiontext as a prefix to tat cell's data, then...
Code:
   Activecell.Value = SubstitutionText + Selection.Value
Skip,
metzgsk@voughtaircraft.com
 
What row/column does your data start in?
Do you have 2 columns of data?
What is the format of the results and where are they stored?
I believe that your task could be represented much more simply than you have stated.
Prpbably could fit in a few lines like this assuming that the ActiveCell is the TopLeft cell in the range...
Code:
    Dim rng As Range, cell As Range
    With ActiveCell
        FirstRowInRange = .Row
        LeftMostColumn = .Column
    End With
    Set rng = Range(Cells(FirstRowInRange, LeftMostColumn), _
                             Cells(FirstRowInRange, LeftMostColumn).End(xlDown))
    For Each cell In rng
        With cell
            'here's where the text formatting takes place
        End With
    Next cell
:) Skip,
metzgsk@voughtaircraft.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top