Write a Macro

New Student 2020

New Member
Joined
Sep 1, 2020
Messages
9
Office Version
  1. 365
Platform
  1. Windows
Hi
I work with various worksheets for stock control in out store and as the column in each sheet is updated regularly downwards so I would like to be able to get the latest value from the column ( same in each sheet = G) copy and paste it in the main worksheet (Products List) against each product name (B2)... I have started the code to find the last cell with value in one sheet as follows:
Sub Last_Col ()
Range (“G100000”).End(xlUp). Select

But I do not know how to copy the value and paste it in B2!??
Also if I want to run the same macro for all my sheets how can I do it and copy each value to a different cell in sheet ProductsList ?
Thank you very much for your help
Franco
 
I can't download the file, it sends me an error.
Did you share the file?

Forget it, I already downloaded the file.
 
Upvote 0

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Try this:

VBA Code:
Sub LastValue()
  Dim sh1 As Worksheet, sh As Worksheet
  Dim f As Range
  
  Set sh1 = Sheets("Product List")
  For Each sh In Sheets
    Set f = sh1.Range("A:A").Find(sh.Name, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      f.Offset(, 1).Value = sh.Range("G" & Rows.Count).End(3).Value
    Else
      Set f = sh1.Range("A:A").Find(sh.Name, , xlValues, xlPart, , , False)
      If Not f Is Nothing Then
        f.Offset(, 1).Value = sh.Range("G" & Rows.Count).End(3).Value
      End If
    End If
  Next
End Sub
 
Upvote 0
Im glad to help you, thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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