I'm still struggling

ColdGeorge

Active Member
Joined
Aug 21, 2012
Messages
412
Office Version
  1. 2016
Platform
  1. Windows
Hi all
The code shown below is working just fine

Code:
Private Sub Workbook_Open()
Worksheets("Publicaciones").Activate
Dim celda As Range
For Each celda In Worksheets("Publicaciones").Range("B2:B1000")
  If celda.Value = Date Then
      celda.Select
  End If
  Next
Application.Goto Selection, scroll:=True
ActiveWindow.ScrollColumn = 1
End Sub

This one is not, I'd like to know why, can you help?

Code:
Private Sub Workbook_Open()
Worksheets("Publicaciones").Activate
Dim celda As Range

Dim lastrow As Long
lastrow = Cells(Rows.Count, 1).End(xlUp).Row

Dim rng As Range
Set rng = Range("B" & lastrow)

For Each celda In rng
   If celda.Value = Date Then
       celda.Select
   End If
   
   Next
 
Application.Goto Selection, scroll:=True
ActiveWindow.ScrollColumn = 1
End Sub

Any suggestion? thanks in advance.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
VBA Code:
Set rng = Range("B" & lastrow)
Is a single cell, is that right?

Probably you meant
VBA Code:
Set rng = Range("B2:B" & lastrow)
 
Upvote 0
Solution
Hi MARK858, thanks for your help

This is the final working code

VBA Code:
Private Sub Workbook_Open()
Worksheets("Publicaciones").Activate
Dim celda As Range

Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row

Dim rng As Range
Set rng = Range("B2:B" & lastrow)

For Each celda In rng
   If celda.Value = Date Then
       celda.Select
   End If
    
   Next
  
Application.Goto Selection, scroll:=True
ActiveWindow.ScrollColumn = 1
End Sub

Thanks, ColdGeorge
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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