If test true, insert cells moving down

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 above made-up example above may lose its formatting here but I think you will get the drift. Column A has a list of 9 Greek words WITH punctuation in separate cells making a total of 12 cells in column A. 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. It is essential I be able to identify specific punctuation marks. I note that some Greek words are only one letter long. I am not a programmer and so my attempt at the macro below which does not work.

Sub Macro1()
Dim x As Integer
For x = 1 To 12
If RxC1 = "," Or RxC1 = "." Or RxC1 = "?" Then 'test if punctuation occurs
Range(Cells(x, 2), Cells(x, 3)).Select 'if punctuation occurs select cells in columns 2 & 3 for row in question
Selection.Insert Shift:=xlDown 'insert cells moving all cells down
End If
Next x
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Hi Paul, I think you are on the right track but instead of this line

If RxC1 = "," Or RxC1 = "." Or RxC1 = "?" Then 'test if punctuation occurs

try this:

If (Range("A" & x).Value = "." Or Range("A" & x).Value = "," Or Range("A" & x).Value = "?") Then 'test if punctuation occurs


In fact you code should look something like this:
Code:
Sub Macro1()
Dim x As Integer
For x = 1 To 12
If (Range("A" & x).Value = "." Or Range("A" & x).Value = "," Or Range("A" & x).Value = "?") Then 'test if punctuation occurs
    Range(Cells(x, 2), Cells(x, 3)).Insert Shift:=xlDown
End If
Next x
End Sub
 
Upvote 0
Hello PaulCruice
Another method for this would be to use select case.(ie.)
Code:
Sub ItsAllGreekToMe()

Dim LstRw As Long, Rw As Long
LstRw = Cells(Rows.Count, "A").End(xlUp).Row

For Rw = 1 To LstRw
  Select Case Cells(Rw, "A").Value
    Case "."
      Cells(Rw, "A").Offset(, 1).Resize(, 2).Insert Shift:=xlDown
    Case ","
      Cells(Rw, "A").Offset(, 1).Resize(, 2).Insert Shift:=xlDown
    Case "?"
      Cells(Rw, "A").Offset(, 1).Resize(, 2).Insert Shift:=xlDown

    'Add any other cases you like here

  End Select
Next Rw
End Sub
 
Upvote 0
HalfAce,
Thanks also. My next task was to find out how to automatically find the Last Row in a column and you gave me that. So thanks heaps.
Paul
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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