S
Sethaholic
Hi,
I'm relatively new to vba and have been struggling to perform a macr
that looks through all worksheets instead of a specific worksheet (i.
"Leon" or "Lee") I indicate. What I am trying to do here is to matc
account numbers in one workbook with account numbers in anothe
workbook ("text"). If they match, then I want it to copy specifi
columns from one to another. The code works, but I can only get it t
do it for each specific worksheet, meaning that I would have to chang
it from "Leon" to "Lee" if I want it to perform the macro for "Lee."
tried using the "For each sh in thisworkbook.worksheets" but don't kno
where to go from there. Please help. Here's my code so far. Thanks i
advance!
Sub ExtractData()
Dim intRec As Integer, rngData As Range, rngItem As Range, rngCom
As Range, rngOut As Range
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Leon")
Set rngData = .Range("C33:C"
.Range("C60").End(xlUp).Row).SpecialCells(xlCellTypeConstants)
End With
With Workbooks("text").Worksheets("sheet1")
Set rngComb = .Range("A1:A" & .Range("A65536").End(xlUp).Row)
End With
For Each rngItem In rngComb
If rngItem = "stop" Then Exit Sub
Set rngOut = rngData.Find(What:=rngItem)
If Not rngOut Is Nothing Then
rngOut.Offset(0, 2).Value = rngItem.Offset(0, 4).Value
rngOut.Offset(0, 3).Value = rngItem.Offset(0, 5).Value
rngOut.Offset(0, 4).Value = rngItem.Offset(0, 6).Value
rngOut.Offset(0, 5).Value = rngItem.Offset(0, 7).Value
Else
End If
Next rngItem
Application.ScreenUpdating = True
End Su
I'm relatively new to vba and have been struggling to perform a macr
that looks through all worksheets instead of a specific worksheet (i.
"Leon" or "Lee") I indicate. What I am trying to do here is to matc
account numbers in one workbook with account numbers in anothe
workbook ("text"). If they match, then I want it to copy specifi
columns from one to another. The code works, but I can only get it t
do it for each specific worksheet, meaning that I would have to chang
it from "Leon" to "Lee" if I want it to perform the macro for "Lee."
tried using the "For each sh in thisworkbook.worksheets" but don't kno
where to go from there. Please help. Here's my code so far. Thanks i
advance!
Sub ExtractData()
Dim intRec As Integer, rngData As Range, rngItem As Range, rngCom
As Range, rngOut As Range
Application.ScreenUpdating = False
With ThisWorkbook.Worksheets("Leon")
Set rngData = .Range("C33:C"
.Range("C60").End(xlUp).Row).SpecialCells(xlCellTypeConstants)
End With
With Workbooks("text").Worksheets("sheet1")
Set rngComb = .Range("A1:A" & .Range("A65536").End(xlUp).Row)
End With
For Each rngItem In rngComb
If rngItem = "stop" Then Exit Sub
Set rngOut = rngData.Find(What:=rngItem)
If Not rngOut Is Nothing Then
rngOut.Offset(0, 2).Value = rngItem.Offset(0, 4).Value
rngOut.Offset(0, 3).Value = rngItem.Offset(0, 5).Value
rngOut.Offset(0, 4).Value = rngItem.Offset(0, 6).Value
rngOut.Offset(0, 5).Value = rngItem.Offset(0, 7).Value
Else
End If
Next rngItem
Application.ScreenUpdating = True
End Su