I am working on generating some automated reports. To reiterate, I would like my code to look at each "string" in Sheet1 column E (ignoring blanks), search for that value in another sheet/workbook, and paste the "single" contained in Sheet1 column D (ignoring blanks, if E is blank, D will be blank) to the left of the string found in the search earlier.
The receiving data sheets are widely dispersed and in a variety of formats, but the one constant is that each position for data input has a unique tag in an adjacent column that is also found in the primary data storage sheet. I don't have that much experience in VBA yet, and was wondering how some others would solve this problem in a dynamic way that wont break the minute a new column is added.
My current code is a jumbled mess, so any pointers, ideas, general strategies would be appreciated. I am trying to get away from using Sheets().select and other references like this, but I'm not sure how to do that yet.
Dim location As String
Dim rownum As Integer
Dim cellfinder As Integer
Sheets("Sheet2").Select 'Ensures that we start on sheet 2
rownum = Range("G2").Value
For cellfinder = 1 To rownum 'Loop goes for as many non-blank rows exist in column---- need
'to add code to skip over blank rows with offset function or else loop will not go on long enough.
Sheets("Sheet2").Select 'selects Pi tag data sheet
'hopefully adjusts the active cell relative to the loop count
If ActiveCell.Value = "" Then 'hopefully detects blank cells and skips to next loop
GoTo Skip
End If
location = ActiveCell.Value 'calls the location tag string the variable "location"
ActiveCell.Offset(0, -1).Select 'offsets from location tag to the "current value column"
ActiveCell.Value.Copy 'copies the value found in the current value column hopefully not the pi function
Sheets("Sheet1").Select 'Selects EOM sheet, can be whatever sheet we wish, or in another worksheet
Range("A1").Select 'establishes a starting point for find function
Cells.Find(What:="location", After:=sht2.cells(1,1), LookIn:= _
xlFormulas, LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:= _
xlNext, MatchCase:=False, SearchFormat:=False).Activate
ActiveCell.Offset(0, -1).Select 'offsets the active cell to the value column in EOM sheet
ActiveCell.Paste 'pastes the activecell value copied from sheet 1
' find function finds the string saved to the location variable , makes it the active cell.
Skip:
Next cellfinder