Need help resolving error in defining last row

  • Thread starter Thread starter clmarquez
  • Start date Start date
C

clmarquez

Help...inexperienced Excel VB programmer at work...

I can't seem to figure out why my code below generates an error at the
"LastCol" definition line. Can anyone help me out? Thanks!

Also, as you can probably tell from the code, I am wanting to clear
cells in the range that contain certain text - is there a simpler way
to do this, rather than having each separate If/EndIf section?


Dim DataTable As Range
Dim LastRow As Long
Dim LastCol As Long

Application.ScreenUpdating = False
Sheets("Training Record").Select
ActiveSheet.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
LastRow = Range("A10").End(xlDown).Row
LastCol = Range("K1").End(x1toright).Column
Set DataTable = Range("K10", cells(LastRow & LastCol))

For Each cell In DataTable
If cell.Value = "a/r" Then
cell.ClearContents
End If

If cell.Value = "core" Then
cell.ClearContents
End If

If cell.Value = "inv" Then
cell.ClearContents
End If

If cell.Value = "opt" Then
cell.ClearContents
End If

Next
 
You could try:

Dim DataTable As Range
Dim LastRow As Long
Dim LastCol As Long

Application.ScreenUpdating = False
Sheets("Training Record").Select
ActiveSheet.Outline.ShowLevels RowLevels:=2, ColumnLevels:=2
LastRow = Range("A10").End(xlDown).Row
LastCol = Range("K1").End(xlToRight).Column
Set DataTable = Range("K10", Cells(LastRow & LastCol))

For Each cell In DataTable
Select Case cell.Value
Case "a/r", "core", "inv", "opt"
cell.ClearContents
End Select

Next cell

Hope this helps
Rowan
 
I guess I should copy and paste code, rather than type it in! The "1"
looks just like the letter "l" in the VB window...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top