samanthareed2012
New Member
- Joined
- May 2, 2014
- Messages
- 9
I'm very new to VBA. I've done my best to copy and paste from forums like this one and then alter it for my purposes, but obviously that can only get you so far.
I am trying to get the following code to repeat adding the rows and the text for every time the word "Date" appears in column c. I keep getting the error message: Next without For, which I don't understand because I have both. Please help!
I am trying to get the following code to repeat adding the rows and the text for every time the word "Date" appears in column c. I keep getting the error message: Next without For, which I don't understand because I have both. Please help!
Code:
Dim GCell As Range
Dim Txt As Range
Dim Rng As Long
Dim LastRow As Long
Dim ColumnC As Range
'Find DATE fields and activate cells
For Each Txt In ColumnC
With Txt
If Txt = "Date" Then
Set GCell = ActiveSheet.Cells.Find(Txt)
Range("$A$1:$AG$28").Find(Txt).Activate
'Move one cell to the right and enter text
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Enter valid date: 12/MAY/2014" & ActiveCell.Value
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Accepts Input"
'Insert new row
Rng = 1
Range(ActiveCell.Offset(1), ActiveCell.Offset(Val(Rng), 0)).EntireRow.Insert
'Move one cell down and enter text
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = "Enter year prior to the lower bound: 12/MAY/2012"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Receive message: The year given is outside the expected date range."
Rng = 1
Range(ActiveCell.Offset(1), ActiveCell.Offset(Val(Rng), 0)).EntireRow.Insert
'Next row
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = "Enter year equal to the lower bound: 12/MAY/2014"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Accepts Input"
Rng = 1
Range(ActiveCell.Offset(1), ActiveCell.Offset(Val(Rng), 0)).EntireRow.Insert
'Next row
ActiveCell.Offset(1, -1).Select
ActiveCell.Value = "Enter year after to the upper bound: 12/MAY/2016"
ActiveCell.Offset(0, 1).Select
ActiveCell.Value = "Receive message: The year given is outside the expected date range."
Rng = 1
Range(ActiveCell.Offset(1), ActiveCell.Offset(Val(Rng), 0)).EntireRow.Insert
Next Txt
Last edited by a moderator: