AccessShell
Board Regular
- Joined
- Sep 5, 2015
- Messages
- 50
- Office Version
- 2003 or older
- Platform
- Windows
I am running Excel on Win 10 Home
In VBA code I am trying to change to a different sheet.
Here is the code
The problem occurs on the highlighted line. The sheet selected does appear on the screen. But the next 2 lines give results for the previous sheet (Dividends).
Can anyone explain what I am doing wrong?
Thanks
In VBA code I am trying to change to a different sheet.
Here is the code
VBA Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim i As Integer
Dim j As Integer
Dim dteExDivDate As Date
Dim curCashAmt As Currency
Dim dteRecDate As Date
Dim dtePayDate As Date
Dim strSymbol As String
Dim intLastRow As Integer
If Target.Address = "$A$1" Then
For i = 2 To 24
Sheets("Dividends").Select
strSymbol = Range("H" & i).Value
dteExDivDate = Range("C" & i).Value
curCashAmt = Range("D" & i).Value
dteRecDate = Range("E" & i).Value
dtePayDate = Range("F" & i).Value
[B][SIZE=5]Sheets(strSymbol).Select[/SIZE][/B]
Debug.Print Range("A" & 7).Value
intLastRow = Range("A" & Rows.Count).End(xlUp).Row
For j = 7 To intLastRow
If Range("A" & j).Value = dtePayDate Then
Range("R" & j).Value = dteExDivDate
Range("S" & j).Value = curCashAmt
Range("T" & j).Value = dteRecDate
Range("U" & j).Value = dtePayDate
End If
Next j
Next i
End If
End Sub
Can anyone explain what I am doing wrong?
Thanks