Find next empty cell in Row 1 and copy paste from another Worksheet

SwiftM

New Member
Joined
Sep 11, 2021
Messages
19
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am really struggling with this, and it's something I worked out in the past but for the life of me cannot work it out again!

I have two worksheets. ws = "Crime" and ws1 = "Log".

In worksheet "Log", in cell "A1" I have typed in "Log No" (which is permanent)

What I am trying to do is when I click a button in "Crime", it finds the next empty cell in Row 1 in "Log" and copies and pastes the value from cell "B2" from worksheet "Crime".

I have tried this code but for some reason inserts the copied value into A11!

Sub Last_Cell()

Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long

'Set variables for copy and destination sheets
Set wsCopy = Sheets("Crime")
Set wsDest = Sheets("Log")


lDestLastRow = wsDest.Cells(1, "A").End(xlUp).Offset(0, 1).Row


wsDest.Range("A1" & lDestLastRow).Value = wsCopy.Range("B2")


End Sub

Obviously, I am doing something wrong so any help would be gratefully appreciated.

Many thanks.
M
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I'm not understanding if you want to copy to the right or down.
It would be clearer if you give examples.

I put the 2 macros to copy to the right and down. Use the one you need.

VBA Code:
Sub copy_to_the_right()
  Sheets("Log").Cells(1, Columns.Count).End(1)(1, 2).Value = Sheets("Crime").Range("B2").Value
End Sub

Sub copy_down()
  Sheets("Log").Cells(Rows.Count, 1).End(3)(2).Value = Sheets("Crime").Range("B2").Value
End Sub

-----
In future please use code tags when posting code.
How to Post Your VBA Code it makes your code easier to read and copy and it also maintains VBA formatting.
 
Upvote 0
I'm not understanding if you want to copy to the right or down.
It would be clearer if you give examples.

I put the 2 macros to copy to the right and down. Use the one you need.

VBA Code:
Sub copy_to_the_right()
  Sheets("Log").Cells(1, Columns.Count).End(1)(1, 2).Value = Sheets("Crime").Range("B2").Value
End Sub

Sub copy_down()
  Sheets("Log").Cells(Rows.Count, 1).End(3)(2).Value = Sheets("Crime").Range("B2").Value
End Sub

-----
In future please use code tags when posting code.
How to Post Your VBA Code it makes your code easier to read and copy and it also maintains VBA formatting.
Fantastic! Thank you Dante!

Apologies, it was copy to the right which i failed to mention. Both work great though..

Thanks again,
M
 
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,194
Members
449,072
Latest member
DW Draft

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