If test is true, select a range and move all below down-2

PaulCruice

New Member
Joined
Aug 18, 2006
Messages
15
GreekWord1 EnglishWord1 Notes1
GreekWord2 EnglishWord2 Notes2
, EnglishWord3 Notes3
GreekWord3 EnglishWord4 Notes4
GreekWord4 EnglishWord5 Notes5
. EnglishWord6 Notes6
GreekWord5 EnglishWord7 Notes7
GreekWord6 EnglishWord8 Notes8
? EnglishWord9 Notes9
GreekWord7
GreekWord8
GreekWord9

The example above loses its formatting here but I think you will get the drift.
Column A has a list of Greek words WITH punctuation in separate cells. Column B & C are the English translation and notes for each Greek word. What I want to do is insert blank cells in Columns B & C to correspond with the punctuation so that the English words and notes properly align with their correct Greek word. My attempt at a macro (below) does not work.

Sub Macro1()
Dim x As Integer
For x = 1 To 9
If RxC1 = "," Then
Range(Cells(x, 2), Cells(x, 3)).Select
Selection.Insert Shift:=xlDown
ElseIf RxC1 = "." Then
Range(Cells(x, 2), Cells(x, 3)).Select
Selection.Insert Shift:=xlDown
ElseIf RxC1 = "?" Then
Range(Cells(x, 2), Cells(x, 3)).Select
Selection.Insert Shift:=xlDown
End If
Next x
End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Hi PaulCruice

Assuming the data start in A1, try:

Code:
Sub PunctIns()
Dim rRng As Range, rCell As Range

Set rRng = Range("A1", Range("A" & Rows.Count).End(xlUp))

For Each rCell In rRng
    If rCell = "." Or rCell = "," Or rCell = "?" Then _
        rCell.Offset(, 1).Resize(, 2).Insert
Next rCell
End Sub

Hope this helps
PGC
 
Upvote 0
pgc01,
Thanks for the reply but I get a syntax error when I try to compile this. Since I'm not any sort of a programmer I don't know where to start looking to rectify it.
Cheers.
 
Upvote 0
Hi PaulCruice

I've just retried the code and got no problem.

I'll tell exactly what I did. Maybe this helps.

1 - I excuted excel creating a new workbook
2 - Copied the data in your post to excel with paste special text

Got this:
Book1
ABCD
1GreekWord1EnglishWord1Notes1
2GreekWord2EnglishWord2Notes2
3,EnglishWord3Notes3
4GreekWord3EnglishWord4Notes4
5GreekWord4EnglishWord5Notes5
6.EnglishWord6Notes6
7GreekWord5EnglishWord7Notes7
8GreekWord6EnglishWord8Notes8
9?EnglishWord9Notes9
10GreekWord7
11GreekWord8
12GreekWord9
Sheet1


3 - Used Data>Text to Columns to separe the data.
Book1
ABCD
1GreekWord1EnglishWord1Notes1
2GreekWord2EnglishWord2Notes2
3,EnglishWord3Notes3
4GreekWord3EnglishWord4Notes4
5GreekWord4EnglishWord5Notes5
6.EnglishWord6Notes6
7GreekWord5EnglishWord7Notes7
8GreekWord6EnglishWord8Notes8
9?EnglishWord9Notes9
10GreekWord7
11GreekWord8
12GreekWord9
13
Sheet1


4 - Called the vba editor (ALT F11 or Tools>Macros>Visula Basic Editor, or right-click on the worksheet tab and choose View Code)

5 - Right-clicked on the workbook's project, in my case VBAProject(Book1) and chose insert>Module. Excel created a module called Module1.

6 - Pasted into Module1 the code I posted before.

7 - Ran the code. Got the following result:
Book1
ABCD
1GreekWord1EnglishWord1Notes1
2GreekWord2EnglishWord2Notes2
3,
4GreekWord3EnglishWord3Notes3
5GreekWord4EnglishWord4Notes4
6.
7GreekWord5EnglishWord5Notes5
8GreekWord6EnglishWord6Notes6
9?
10GreekWord7EnglishWord7Notes7
11GreekWord8EnglishWord8Notes8
12GreekWord9EnglishWord9Notes9
13
Sheet1


I hope this helps. If not, please post details. Which line, which compile error message, etc.

Kind regards
PGC
 
Upvote 0

Forum statistics

Threads
1,215,544
Messages
6,125,441
Members
449,225
Latest member
mparcado

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