Writing a Macro

babykilers

New Member
Joined
Oct 18, 2024
Messages
2
Office Version
  1. 2021
Platform
  1. Windows
Dear all Excel Experts,
How are you and hope that you guys can help me on this.
In Sheet 1 - I have a table that will be in every day update ( number of rows will be different in each day ) .
- In the first column of table will be number 1,2,3,4,5... to the last row of table .

In Sheet 2 - I will do some calculation based on information founded in the table (Sheet 1 )
- In cell B2 will be criteria that look up the informations
- In cell B2 will be number from first column of table in Sheet 1
In sheet 3 - I will save data after calculation

I am trying to write a Macro to do the following:
1. Copy individually numbers from first column ( Sheet 1 ) beginning with first number (cell B11 ) to the end
2. Paste in cell B2 ( Sheet 2 )
After excel make all calculation ...
3. Run an macro ( I already wrote it ) named "Archive"
4. Repeat
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
You will need to modify based on your need but this can give you a good start
VBA Code:
Sub Test()
    'Copy Range from Sheet1 to Sheet2
    Worksheets("Sheet2").Range("B2:B" & Rows.Count).ClearContents
    lr = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
    Worksheets("Sheet1").Range("B11:B" & lr).Copy Worksheets("Sheet2").Range("B2")
   
    'Run another macro
    Call Archive
End Sub
 
Upvote 0
You will need to modify based on your need but this can give you a good start
VBA Code:
Sub Test()
    'Copy Range from Sheet1 to Sheet2
    Worksheets("Sheet2").Range("B2:B" & Rows.Count).ClearContents
    lr = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
    Worksheets("Sheet1").Range("B11:B" & lr).Copy Worksheets("Sheet2").Range("B2")
  
    'Run another macro
    Call Archive
End Sub
This wiil work for copy and paste for entire column in one move but i want to copy each number from column an run macro after past and then copy next number and run again macro after past ... repeat to last number .
 
Upvote 0
VBA Code:
Sub Test()
    'Copy Range from Sheet1 to Sheet2
    lr1 = Worksheets("Sheet1").Range("B" & Rows.Count).End(xlUp).Row
    lr2 = Worksheets("Sheet2").Range("B" & Rows.Count).End(xlUp).Row
   
    For i = 11 To lr1
        Worksheets("Sheet2").Range("B" & lr2 + 1).Value = Worksheets("Sheet1").Range("B" & i).Value
         'Run another macro
         Call Archive
        lr2 = lr2 + 1
    Next i
  
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,259
Messages
6,177,485
Members
452,782
Latest member
ZCapitao

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