ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Removie .select (https://www.excelbanter.com/excel-programming/428730-removie-select.html)

Brad

Removie .select
 
The below works - but is there a better way? It seems that I had to add the
..select to make it work regardless on sheet was previously active - then I
forced another worksheet to be active.

Sub AddNewWeek()
Dim LastRow As Long
shtGraphData.Select
With Sheets("Graph_Data")
If Range("Z6").Value Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
shtInput.Select
End Sub


Sam Wilson

Removie .select
 
You were missing the . in front of your Range

Sub AddNewWeek()
Dim LastRow As Long
With Sheets("Graph_Data")
If .Range("Z6").Value .Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = .Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
End Sub


"Brad" wrote:

The below works - but is there a better way? It seems that I had to add the
.select to make it work regardless on sheet was previously active - then I
forced another worksheet to be active.

Sub AddNewWeek()
Dim LastRow As Long
shtGraphData.Select
With Sheets("Graph_Data")
If Range("Z6").Value Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
shtInput.Select
End Sub


Dominik Petri

Removie .select
 
Brad schrieb:
The below works - but is there a better way? It seems that I had to add the
.select to make it work regardless on sheet was previously active - then I
forced another worksheet to be active.

Sub AddNewWeek()
Dim LastRow As Long
shtGraphData.Select
With Sheets("Graph_Data")
If Range("Z6").Value Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
shtInput.Select
End Sub


Brad,

if Range("Z6") and Range("Z5") are on shtGraphData, you need to add a
dot before the Range:

If .Range("Z6").Value .Range("Z5").Value Then

same he
Cells(LastRow + 1, "K").Value = .Range("Z6").Value

Then no selection should be necessary.

Regards,
xlDominik.

Brad

Removie .select
 
Aaaarrrrggh (missing a period). I will check this tomorrow - but that makes
sense

Thank you, very much!!!!


"Sam Wilson" wrote:

You were missing the . in front of your Range

Sub AddNewWeek()
Dim LastRow As Long
With Sheets("Graph_Data")
If .Range("Z6").Value .Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = .Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
End Sub


"Brad" wrote:

The below works - but is there a better way? It seems that I had to add the
.select to make it work regardless on sheet was previously active - then I
forced another worksheet to be active.

Sub AddNewWeek()
Dim LastRow As Long
shtGraphData.Select
With Sheets("Graph_Data")
If Range("Z6").Value Range("Z5").Value Then
LastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
.Cells(LastRow + 1, "K").Value = Range("Z6").Value
.Cells(LastRow, "L").Resize(1, 6).Copy .Cells(LastRow + 1, "L")
End If
End With
shtInput.Select
End Sub



All times are GMT +1. The time now is 04:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com