Modifying a code used to auto populate in a loop.

tony0217

Board Regular
Joined
Aug 31, 2012
Messages
134
I currently have a code that I have used before to auto populate a cell in a worksheet.

I have a list of cells that I need to populate.

there are two lists on sheet 2.
the first list is in column C.
the second list is in column J.

the cells that need to be populated from column C sheet 2, to the cells in sheet 1 are:
C6
B81
F84
F85
B88
D97.

the cells that need to populated from column J sheet 2, to the cells in sheet 1 are:
f66.

the code below does work for colum C.

what i need to do is modify how to use more than one list to populate the cells.

Also would you please show me how to break this down just in case i need to add another list?

Thank you.


The below code populates cell c13 with a value from the list in sheet 2, saves the file as the value of c13 and then moves on to the next value in the list and over and over again.












Code:
Sub MM1()
Dim sh1 As Worksheet, sh2 As Worksheet, c As Range
Set sh1 = Sheets("Sheet1")
Set sh2 = Sheets("Sheet2")
For Each c In sh2.Range("A1", sh2.Cells(Rows.Count, 1).End(xlUp))
    If c <> "" Then
        sh1.Range("c13") = c.Value
        fname = c.Value
        ActiveWorkbook.SaveCopyAs "C:\data\" & fname & ".xls" 'change path to suit
    End If
Next c
 sh2.Range("A1", sh2.Cells(Rows.Count, 1).End(xlUp)).ClearContents
End Sub
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Forum statistics

Threads
1,214,402
Messages
6,119,301
Members
448,885
Latest member
LokiSonic

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