Can someone explain why this code is writing yes in column 27 instead of column 14?

supermom28115

New Member
Joined
May 9, 2022
Messages
43
Office Version
  1. 365
Platform
  1. Windows
VBA Code:
Public Sub birthLoops()
'this code checks for record and birth location notes and copies if needed

Dim x As Range, y As Range, record As Variant, birth As Variant
Dim startrow As Integer, i As Integer, endrow As Integer

    endrow = Cells(Rows.Count, 14).End(xlUp).Row
 
    For i = 3 To endrow
    Set y = Cells(i, 14)
    Set x = Cells(i, 13)
    'for true answers it should evaluate the next line? for false it finds else or end and then the next line?
            If IsEmpty(y(i, 14).Value2) Then    'this is supposed to look at the cell and say true to empty?
                         If LCase(x(i, 13).Value2) = "yes" Then  'this is supposed to look at the value of the cell and if they match say true?
                              Set birth = Range(y(i, 14).Offset(0, 2), y(i, 14).Offset(0, 4))
                              Set record = Range(y(i, 14).Offset(0, -4), y(i, 14).Offset(0, -2))
                              birth.Value = record.Value
                        End If
                        If LCase(y(i, 14).Value2) = "yes" Then
                        Else
                        y(i, 14).Value2 = "yes"  'this is the line, i thought it was not doing this step even though when i stepped through it was doing what i expected
                        End If                             'and was evaluating and, i thought, processing the code. It was after about the 5th time of stepping through and the 
                                                             '2nd time of running the code that I found yes printed in several rows on column AA. 
         End If
    Next i
            
End Sub

I know it has other problems, specifically me having it start at the beginning of the column every time it runs but I just got so frustrated with trying to get the count rows code to work right. I still don't quite understand how the code process works for that particular issue. I don't mind it running repeatedly right now since I only have 10 rows of data right now. I think my row count is also adding a row every time it counts as well. I guess I should also say that I have this set as a table. I thought it would help with coding to be able to name ranges and have them automatically adjust as new records were added, however I ended up throwing the book across my house yesterday when I tried to use named ranges in the code. This is the dropbox link to the file as I am working on it now.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,507
Messages
6,179,176
Members
452,893
Latest member
denay

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