Stumped on (Simple?) VBA Question

  • Thread starter Thread starter steveski
  • Start date Start date
S

steveski

I know this code is wrong, but I’m still a rookie, only slightly mor
skilled than when I joined.

This code resides in a sheet called “TAT by Priority”, but I’m tryin
to poll a different sheet in the same workbook called “Data Entry”. Ho
can I get pointed to the “Data Entry” sheet before executing th
For/Next Loop?

Worksheets("Data Entry").Cells ("PTSource")
LastRow = ActiveSheet.UsedRange.Rows.Count
For i = 1 To LastRow
If Cells(i, 9).Value Then 'start flag is true
If Cells(i, 8).Value = "E" Then
c1 = c1 + 1
ElseIf Cells(i, 8).Value = "O" Then
c2 = c2 + 1
End If
End If
Next
 
And if you do a lot of that in your code you may also want to set references up
at the start and then use those throughout, which will also make it a lot easier
if you change the sheet names at any time, as you only have to change it in one
place, eg:-

Dim shtTat As Worksheet
Dim shtDat As Worksheet

Set shtTat = Sheets("Tat By Priority")
Set shtDat = Sheets("Data Entry")

If shtTat.cells(i,9).value then
if shtDat.cells(i,8).value = "E" then....
 
Back
Top