Macro to find string, copy column below string found to insert in column on same active worksheet

Hi!

I keep on getting message "object variable or With block variable not set" for the code below. Note, however, that this code works great with only four iterations...when I add a fifth it gets confused. Any help? Also, if there is a better way, rather than 'selecting' the column to past to, by all means please let me know. Thank you!

Sub Macro2()

Dim uRange As Range
Dim FindTopic As Range
Dim tCol As Integer

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("Stdnt Name")
Columns(FindTopic.Column).Cut
Columns(1).Select
ActiveSheet.Paste

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("Term Ld")
Columns(FindTopic.Column).Cut
Columns(2).Select
ActiveSheet.Paste

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("Reg Type Cd")
tCol = FindTopic.Column
Columns(tCol).Cut
Columns(3).Select
ActiveSheet.Paste

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("Stdnt Nyu Id")
tCol = FindTopic.Column
Columns(tCol).Cut
Columns(4).Select
ActiveSheet.Paste

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("PeopleSoft ID")
tCol = FindTopic.Column
Columns(tCol).Cut
Columns(5).Select
ActiveSheet.Paste

End Sub

Vishesh's picture

Try this...Set uRange =

On which line its giving error ?

Try this...

Set uRange = ActiveSheet.UsedRange
Set FindTopic = uRange.Find("PeopleSoft ID")
tCol = FindTopic.Column
ActiveSheet.Columns(tCol).Cut
ActiveSheet.Columns(5).PasteSpecial xlPasteAll

Simple answer

The object that I was looking for simply didn't exist...that is to say that there was an extra space in the string-the computer didn't recognize it therefore. Now it's all fixed, but thanks!