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

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I need his book, where is that available at? Thank you so much for the link.

I can't remember Chip ever writing a book, Chip's topic index with links is below (Alan Beban [who wrote that article Chip reposted] you'll find a few things on the web about, but I doubt a book these days)

CPearson.com Topic Index
 
Upvote 0

Forum statistics

Threads
1,214,391
Messages
6,119,244
Members
448,879
Latest member
VanGirl

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