Jared_Jones_23
New Member
- Joined
- Jun 24, 2011
- Messages
- 34
Right now the data I am using is stored in a table. When its like this it will not let me copy a row and insert it but if you convert it to a range it works fine. However, once I convert it to a range and run the following macro it deletes a row of information that isn't even in the range thats being altered. It happens in the red text and that is using the cells from row 20 down but my information in row 19 gets erased. Any ideas?
Thank you,
Jared
Sub Macro_1() 'Highlights empty mandatory cells
Dim myarray As Variant
Dim lastRow, lastCol As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
myarray = Array(1, 2, 7, 8, 12, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26) 'mandatory columns
count = 0
With ActiveSheet
lastRow = .Cells(.Rows.count, "D").End(xlUp).Row 'Finds last row and column
lastCol = .Cells(20, .Columns.count).End(xlToLeft).Column
End With
Range(Cells(20, 1), Cells(lastRow, lastCol)).Interior.ColorIndex = 0
For r = 20 To lastRow 'Finds empty mandatory cells and colors them
If Cells(r, 4) <> "" Then
For Each xVal In myarray
If Cells(r, xVal) = "" Then
Cells(r, xVal).Interior.ColorIndex = 28
count = count + 1
End If
Next xVal
End If
Next r
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub <!-- / message -->
Thank you,
Jared
Sub Macro_1() 'Highlights empty mandatory cells
Dim myarray As Variant
Dim lastRow, lastCol As Integer
With Application
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
myarray = Array(1, 2, 7, 8, 12, 14, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26) 'mandatory columns
count = 0
With ActiveSheet
lastRow = .Cells(.Rows.count, "D").End(xlUp).Row 'Finds last row and column
lastCol = .Cells(20, .Columns.count).End(xlToLeft).Column
End With
Range(Cells(20, 1), Cells(lastRow, lastCol)).Interior.ColorIndex = 0
For r = 20 To lastRow 'Finds empty mandatory cells and colors them
If Cells(r, 4) <> "" Then
For Each xVal In myarray
If Cells(r, xVal) = "" Then
Cells(r, xVal).Interior.ColorIndex = 28
count = count + 1
End If
Next xVal
End If
Next r
With Application
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub <!-- / message -->