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!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
If you are looking to insert a column 2 columns from where it found the value, what about:
Code:
myR.Offset(,2).Insert xltoRight
 
Upvote 0

Forum statistics

Threads
1,215,050
Messages
6,122,868
Members
449,097
Latest member
dbomb1414

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top