M
marlea
Hi-
I need to move data from workbook1 to workbook2 based on the content
of Column C in workbook1. Column C contains book titles. If the titl
contains the words "Unit Resource Book", then the macro should pul
data in other columns and populate workbook2.
The problem with my macro below is that it will pull data for title
that contain *only* the words "Unit Resource Book." How should I alte
my SELECT statement so that it isn't only looking for an exact match
i.e., I want it to find all titles that contain the words "Uni
Resource Book." Thank you!
Title examples:
Physical Science Unit Resource Book
Physical Science Unit Tests
Anatomy Unit Resource Book
Physioloy
Sub titles_Test2()
' Declare variables...
Dim bk1 As Workbook, bk2 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet
Dim pgStart, pgEnd, newRow, counter As Integer
Dim activityTitle, activityID, pgRng, book, pdfName, ansKey As String
Dim rng1 As Range, cell As Range
Set bk1 = Workbooks("book1.xls")
Set bk2 = Workbooks("book2.xls")
Set sh1 = bk1.Worksheets("sheet1")
Set sh2 = bk2.Worksheets("sheet1")
Set rng1 = sh1.Range(sh1.Cells(2, 3), sh1.Cells(2, 3).End(xlDown))
newRow = 18
For Each cell In rng1
sh1.Activate
ActiveSheet.Range("C2").Select
' Get book
book = cell.Offset.Value
' Get page start
pgStart = cell.Offset(0, 1).Value
' Get page end
pgEnd = cell.Offset(0, 2).Value
' Get title
activityTitle = cell.Offset(0, 3).Value
' Get pdfName...
pdfName = cell.Offset(0, 8).Value
If pgEnd = pgStart Then
pgRng = pgStart
Else
pgRng = pgStart & "-" & pgEnd
End If
Select Case book
Case Is = "Unit Resource Book"
sh2.Cells(newRow, 3).Value = "English"
sh2.Cells(newRow, 7).Value = activityTitle
sh2.Cells(newRow, 8).Value = book
sh2.Cells(newRow, 12).Value = pgRng
sh2.Cells(newRow, 13).Value = pdfName
End Select
newRow = newRow + 1
Next
sh2.Activate
ActiveSheet.Range("A1").Select
End Su
I need to move data from workbook1 to workbook2 based on the content
of Column C in workbook1. Column C contains book titles. If the titl
contains the words "Unit Resource Book", then the macro should pul
data in other columns and populate workbook2.
The problem with my macro below is that it will pull data for title
that contain *only* the words "Unit Resource Book." How should I alte
my SELECT statement so that it isn't only looking for an exact match
i.e., I want it to find all titles that contain the words "Uni
Resource Book." Thank you!
Title examples:
Physical Science Unit Resource Book
Physical Science Unit Tests
Anatomy Unit Resource Book
Physioloy
Sub titles_Test2()
' Declare variables...
Dim bk1 As Workbook, bk2 As Workbook
Dim sh1 As Worksheet, sh2 As Worksheet
Dim pgStart, pgEnd, newRow, counter As Integer
Dim activityTitle, activityID, pgRng, book, pdfName, ansKey As String
Dim rng1 As Range, cell As Range
Set bk1 = Workbooks("book1.xls")
Set bk2 = Workbooks("book2.xls")
Set sh1 = bk1.Worksheets("sheet1")
Set sh2 = bk2.Worksheets("sheet1")
Set rng1 = sh1.Range(sh1.Cells(2, 3), sh1.Cells(2, 3).End(xlDown))
newRow = 18
For Each cell In rng1
sh1.Activate
ActiveSheet.Range("C2").Select
' Get book
book = cell.Offset.Value
' Get page start
pgStart = cell.Offset(0, 1).Value
' Get page end
pgEnd = cell.Offset(0, 2).Value
' Get title
activityTitle = cell.Offset(0, 3).Value
' Get pdfName...
pdfName = cell.Offset(0, 8).Value
If pgEnd = pgStart Then
pgRng = pgStart
Else
pgRng = pgStart & "-" & pgEnd
End If
Select Case book
Case Is = "Unit Resource Book"
sh2.Cells(newRow, 3).Value = "English"
sh2.Cells(newRow, 7).Value = activityTitle
sh2.Cells(newRow, 8).Value = book
sh2.Cells(newRow, 12).Value = pgRng
sh2.Cells(newRow, 13).Value = pdfName
End Select
newRow = newRow + 1
Next
sh2.Activate
ActiveSheet.Range("A1").Select
End Su