VBA Help - Copy data from One Sheet to Another as a Loop - Excel 2016

Johnny Thunder

Well-known Member
Joined
Apr 9, 2010
Messages
693
Office Version
  1. 2016
Platform
  1. MacOS
Hello,


I am working on a project that will be looking at a datasource and trying to match up Model ID's onto another sheet in the same workbook and then copying over the Model Name if it finds the value. If not, it will look to the lastrow of the 2nd sheet and add the New Model ID and Model name.


Report Attributes:
Sheets("DataSource") - Table with Lookup values
Sheets("Manual Adjustment") - Sheet to search and add Model Name too if ID is matched


On Datasource sheet, the Id's start on "A11:A90" with some blanks in between - Will need to be dynamic enough to reset the last row of data
On Datasource sheet, the Model Names are in column "E11:E90"


On the Manual Adjustments sheet, the Model ID's to match to are on Column "A5:A400" - Will need to be dynamic enough to always search for the new lastrow if ID's are added
On the Manual Adjustments sheet, the Model Names that will be inserted by the code will need to be added to the Row of the matched ID and Column H.


Please let me know if the above is clear. Any help is appreciated.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
@cerfani

This is all I got
Code:
Option Explicit
Sub Move_Data()


Dim cell     As Range, Results As Range
Dim ws1     As Worksheet, ws2 As Worksheet


Set ws2 = Sheets("Datasource") 'DataSource
Set ws1 = Sheets("Manual Adjustment") 'Sheet to insert new values if found


LastRow = ws2.Cells(Rows.Count, "A").End(xlUp).Row
Set Results = ws2.Range("A11:A" & LastRow & "")


For Each cell In Results


'Enter code to do the search and if the value is found enter the Model Name in Column H on ws1
'If Model ID is not found, then go to lastrow on sheet ws1 and add ID to column A and Model Name to Column H


'Loop


End Sub
 
Upvote 0
ok but your explanation is a little tough to follow...

You say you have 80 unique models with ID and name on a data sheet.

You also have a list of 396 model IDs that you want to retrieve the name for. If you do not find the ID in the list of 80 then you want to add the model ID to the list of 80 and to add the name.

Seems like you will have tons of duplicates and for IDs with no match on the data, how will you add it to the data list since you dont know the name? I have a feeling you meant something else but not sure.
 
Upvote 0
@cerfani .... Nothing to add?

ok but your explanation is a little tough to follow...

You say you have 80 unique models with ID and name on a data sheet.

You also have a list of 396 model IDs that you want to retrieve the name for. If you do not find the ID in the list of 80 then you want to add the model ID to the list of 80 and to add the name.

Seems like you will have tons of duplicates and for IDs with no match on the data, how will you add it to the data list since you dont know the name? I have a feeling you meant something else but not sure.
 
Upvote 0

Forum statistics

Threads
1,215,133
Messages
6,123,232
Members
449,092
Latest member
SCleaveland

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