View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Rowan Drummond[_3_] Rowan Drummond[_3_] is offline
external usenet poster
 
Posts: 414
Default Need help resolving error in defining last row

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

clmarquez wrote:
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