Need to do an "xlToRight"-type move in Excel to move right more than one column.

OnAVBALark

New Member
Joined
Mar 7, 2014
Messages
1
Hi! This is my first post, and I haven't been able to find the solution to my exact problem, even though I've found things that seemed similar but didn't work in my case.

I have a very nice piece of VBA that I got from Microsoft Answers: Loop thru one column, find specific text, shift right one column - Microsoft Community. I've used it tons of times already, but I need to tweak the code slightly to replicate the insert xlToRight more than once. Here's a copy of Microsoft's code:

Code:
[SIZE=2][COLOR=#000000][FONT=Tahoma]'Replace the "G" with the appropriate column you wish to search'Replace "TextStringHere" with the string you want to find.[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]
[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]Dim myR As Range[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]Set myR = Range("G:G").Find("TextStringHere")[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]Do While Not myR Is Nothing[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]    myR.Insert xlToRight[/FONT][/COLOR]
[COLOR=#000000][FONT=Tahoma]    Set myR = Range("G:G").FindNext[/FONT][/COLOR]

[/SIZE][COLOR=#000000][FONT=Tahoma][SIZE=2]Loop [/SIZE]
[/FONT][/COLOR]
My table was imported from a pipe-delimited file that did not account for null or blank values, so I mostly need to even up my columns by moving matching data in a cell "x" number of columns to the right.

I've tried:
Code:
myR.Insert xlToRight +2
And
Code:
ActiveCell.Resize(0,2)
Thanks for your help!
 

Scott Huish

MrExcel MVP
Joined
Mar 17, 2004
Messages
19,884
If you are looking to insert a column 2 columns from where it found the value, what about:
Code:
myR.Offset(,2).Insert xltoRight
 

Forum statistics

Threads
1,081,802
Messages
5,361,388
Members
400,628
Latest member
ganeshkhatri

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top