VBA only allows 2 rows then starts to overwrite why?

DMO123

Board Regular
Joined
Aug 16, 2018
Messages
99
Hi All,

i have the below VBA code. when a row is marked as "CLOSED" on another tab the row moves to a new tab. but there seems to be an error with the code as it only allows 2 rows in the new tab then starts to overwrite the rows. any help on how to fix this will be highly appreciated!

Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Value = vbNullString Then Exit Sub
    If Intersect(Target, Columns("S:S")) Is Nothing Then Exit Sub
    Dim bottomA As Long
    bottomA = Sheet16.Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1).End(xlUp).Offset(1).Row
    Application.ScreenUpdating = False
    If Target.Value = "CLOSED" Then
        Target.EntireRow.Copy Sheet16.Cells(bottomA, 1)
        Sheet16.Range("X" & bottomA) = Now
        Sheet16.Range("Y" & bottomA) = Application.UserName
        Target.EntireRow.Delete
    End If
    Sheet16.Columns.AutoFit
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hi,

The highlighted section in Red Bold below will likely go to row 2, try deleting it, or replace with "+1" to go to the next free row?

Hi All,

i have the below VBA code. when a row is marked as "CLOSED" on another tab the row moves to a new tab. but there seems to be an error with the code as it only allows 2 rows in the new tab then starts to overwrite the rows. any help on how to fix this will be highly appreciated!

Code:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Value = vbNullString Then Exit Sub
    If Intersect(Target, Columns("S:S")) Is Nothing Then Exit Sub
    Dim bottomA As Long
    bottomA = Sheet16.Cells(Cells(Rows.Count, 1).End(xlUp).Row, 1)[COLOR="#FF0000"][B].End(xlUp).Offset(1).Row[/B][/COLOR]
    Application.ScreenUpdating = False
    If Target.Value = "CLOSED" Then
        Target.EntireRow.Copy Sheet16.Cells(bottomA, 1)
        Sheet16.Range("X" & bottomA) = Now
        Sheet16.Range("Y" & bottomA) = Application.UserName
        Target.EntireRow.Delete
    End If
    Sheet16.Columns.AutoFit
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
End Sub

Hope this helps,

Eric
 
Upvote 0
A simpler version
Code:
bottomA = Sheet16.Range("A" & Rows.Count).End(xlUp).Offset(1).Row
Does col A on sheet16 always have data?
 
Upvote 0
In that case have you tried my suggestion?
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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