I have two sheets first sheet gets data from SQL table so the range always changes depending on data size I have determined what the range is for cell A2: endxldown
In sheet 2 I have a date form which promts user to enter a date when user enters the date e.g. today, excel needs to enter this date in sheet 2 e.g. sheet 1 has data range of A2:A20 so sheet 2 will enter todays dats in range A2:A20
This gives me range in sheet 1;
Sub findlastrow()
Dim LastRow As Long
With Worksheets("Data").Activate
LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
Range("A1").Resize(LastRow).Select
MsgBox "The data range address is " & Selection.Address(0, 0) & ".", _
vbInformation, "Data-Contatining range address:"
End With
End Sub
Answer = A2:A251
The below code is suppose to enter date in range A2:A251
Sub CreateJnl()
Dim dte As String
Dim LastRow As Long
Dim rng As Range
Dim ws As Worksheet
Application.Calculation = xlManual
Application.ScreenUpdating = False
Sheets("Journal").Cells.ClearContents
Set ws = ThisWorkbook.Sheets("Data")
With ws
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
LastRow = Cells.Find(What:="*", SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
Range("A2").Resize(LastRow).Select
MsgBox "The data range address is " & Selection.Address(0, 0) & ".", _
vbInformation, "Data-Contatining range address:"
Else
LastRow = 1
End If
If Not LastRow < 3 Then
Set rng = .Range("A2:A" & LastRow)
Debug.Print rng.Address
Else
MsgBox "No Data found beyond A3"
End If
End With
dte = InputBox("Please Enter Date: ", Default:=Format(Now, "dd/mm/yyyy"))
Sheets("Journal").rng.Value = dte
Application.ScreenUpdating = True
End Sub